Reputation: 21
How can I prevent multiple 'as const' needing by declaring an interface or a type to solve this issue below?
export const MESSAGES = {
WELlCOME_MESSAGE: 'Wellcome again' as const,
UNALLOWED_MESSAGE: 'You are not allowed' as const,
ALLOWED_MESSAGE: 'You are allowed' as const,
}
Upvotes: 0
Views: 189
Reputation: 66173
Just declare as const
on the object level instead:
export const MESSAGES = {
WELlCOME_MESSAGE: 'Wellcome again',
UNALLOWED_MESSAGE: 'You are not allowed',
ALLOWED_MESSAGE: 'You are allowed',
} as const;
See example on TypeScript Playground.
Upvotes: 6