Skip to content

More ergonomic runtime representation of variants #467

Description

@cristianoc

Is your feature request related to a problem? Please describe.
The following variant declaration

  type abc = { #a; #b; #c };

has this runtime representation:

export type abc =
  { 'a' : null } |
  { 'b' : null } |
  { 'c' : null };

Here are patterns one could try to use for a function to check whether a value represents #a:

if(x.a) ... // wrong
if(x.a == null) ... // wrong
if(x.a === null) ... // right

There's no help that the TypeScript type checker can give to figure out the correct pattern.

Describe the solution you'd like
One possible idiomatic representation, at the cost of some reduced uniformity (variants with no arguments represented differently from variants with arguments):

export type abc = "a" | "b" | "c";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions