Skip to content

Using enums under tstype #51

Answered by gzuidhof
jonamsalem asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @jonamsalem

I don't think this is possible directly, it is hard/impossible to know for the current parser to know all the possible values, at least in its current state (it would have to be a more full compiler).

Here is a posisble workaround, you put

type Status string

in a separate file that you ignore in the Tygo config.

Then in the frontmatter, you manually write out the type:

frontmatter: |
      type Status = "'Pending' | 'Active' | 'Inactive' | 'Unknown'";

Or if you want to be even more strict about it:

  type Status = "typeof Pending | typeof Active | typeof Inactive | typeof Unknown";

Then you would be able to use tstype:"Status".
Of course it's not perfect - but this may just…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jonamsalem
Comment options

Answer selected by jonamsalem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants