There is a constant defined as follows:
const PageTypes = [
'type1',
'type2',
'type3'
] as const;
export type PageType = typeof PageTypes[number]
If I have a string that I want to check for the index of type1
,
mystring.indexOf('type1')
- I'm unsure how to enforce the usage of PageTypes
in this scenario. What if I accidentally misspell it as 'tpe1'
? Is there a way in TypeScript to receive an error or highlight incorrect spellings like 'tpe1'
' in IDE?
Is it possible to achieve this level of enforcement in Typescript?