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

Declare a string type with a set of possible values

I know that the following works:

interface Travel {
  travelClass: 'economy' | 'business' | 'first';
  username?: String;
}

Now, I want to extract the travelClass so that I can reuse it at other places, something like this:-

type TravelClass 'economy' | 'business' | 'first'

However, it is not compiling.

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 :

type requires the use of a =.

type TravelClass  = 'economy' | 'business' | 'first'
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