Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reference constants in type definition

Typescript weirdness:

export type MyType = 0 | 1 | 2;

This works. But this does not:

export const ONE = 1;
export const TWO = 2;
export const THREE = 3;
export type MyType = ONE | TWO | THREE;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With the second example you are in typespace using a value (the declared consts) to declare a type. you need to use typeof ONE TWO or THREE. In the first example, 1 2 and 3 count as types themselves.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading