How to define string literal union type from constants in Typescript - Stack Overflow

PHOTO EMBED

Tue Feb 01 2022 10:51:35 GMT+0000 (UTC)

Saved by @avivdaniel #javascript

const MY_CONSTANT = 'MY_CONSTANT' // must be const, no annotation. let or var will not work
const SOMETHING_ELSE = 'SOMETHING_ELSE' // must be const, no annotation. let or var will not work
type MyType = typeof MY_CONSTANT | typeof SOMETHING_ELSE
content_copyCOPY

https://stackoverflow.com/questions/56263200/how-to-define-string-literal-union-type-from-constants-in-typescript