Skip to content

cvdl-ts: Add proper structural typing #22

@alpaylan

Description

@alpaylan

Currently, a DocumentDataType is a fixed set of choices. Below is the definition from DataSchema.ts

export type Date = { tag: "Date"; format: DateFormat.t };
export type URL = { tag: "Url" };
export type PureString = { tag: "String" };
export type MarkdownString = { tag: "MarkdownString" };
export type PureNumber = { tag: "Number" };
export type Type = { tag: "Type"; value: string };
export type List = { tag: "List"; value: DocumentDataType.t };
export type Types = { tag: "Types"; value: DocumentDataType.t[] };

export type t =
  | Date
  | PureString
  | MarkdownString
  | URL
  | PureNumber
  | Type
  | List
  | Types;

These types are used in conjunction with ItemContent, where each Item will have a datatype specified by its data schema

export type PureString = {
    tag: "String";
    value: string;
};

export type None = {
    tag: "None";
};

export type List = {
    tag: "List";
    value: PureString[];
}

export type Url = {
    tag: "Url";
    value: {
        url: string;
        text: string;
    };
};

export type t = PureString | None | List | Url;

This scheme is obviously very flawed and limited. A better option would be to NOT hardcode these types and design a new system that merges types and their editors, by most possibly using small set of primitives and some mechanisms to define discriminated unions to model sums and products.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions