How do you use a literal in a type declaration?

I’m attempting to make a record type that has an int literal as one of the fields, but can’t quite figure out how to accomplish this. Something like this:

type Entity = {
  version: 0, // Error: "Missing a type here"
  name: string,
}

type Entity1 = {
  version: 1,
  name: string,
  age: int,
}

You can accomplish this with polymorphic variants:

type entity = {
  version: [#0],
  name: string,
}

type entity1 = {
  version: [#1],
  name: string,
  age: int,
}

Maybe you can tell us more about what you’re trying to achieve?

4 Likes

Just marking the version of an evolving type, this was a perfect solution, thanks!