Using enums under tstype #51
-
Hey! Is there any way to use my enum under the tstype label in a struct. For example: say i have an enum :
and under my struct i wanna use rather than having to generate the status label as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 If your union consists of 1000 items, this is of course not really workable - but maybe it's doable to type it manually. |
Beta Was this translation helpful? Give feedback.
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
in a separate file that you ignore in the Tygo config.
Then in the frontmatter, you manually write out the type:
Or if you want to be even more strict about it:
Then you would be able to use
tstype:"Status"
.Of course it's not perfect - but this may just…