DEV Community

Discussion on: TypeScript Tutorial - Use "as const" to export colors!

Collapse
 
snios profile image
snios

Very nice, however i have an issue with trying to implement this.

When declaring av variable type inerhitance makes it so that i cannot change to another color.

Example

Does not work
let color = Colors.GRAY_LIGHT; // Inherits the actual color value as type.
color = Colors.RED; // Red does not have the same value so does not work.

Works but a little annoying to do.
let color: ColorType = Colors.GRAY_LIGHT;
color = Colors.RED;

Anyone have a suggestion on how to "fix" this?