mkenum
v0.1.1
Published
[](https://badge.fury.io/js/mkenum)
Readme
mkenum: make enum type in javascript
Install
Install via npm package:
npm i mkenumUsage
import makeEnum, {type IEnum} from 'mkenum'
const Env = makeEnum('dev', 'stg', 'prod') // return {dev: 'dev', stg: 'stg', prod: 'prod'}
type Env = typeof Env.$ // type 'dev' | 'stg' | 'prod'
const dev = Env.dev // type 'dev'Caveats
.$on the returned object is type-only. It exists in the type signature for convenience (typeof Env.$), but there is no concrete value at runtime — accessingEnv.$will returnundefined.If
'$'is one of the enum values,typeof Env.$resolves to the literal type'$'instead of the union of all values. In that case, derive the union withkeyof typeofinstead:const Env = makeEnum('$', 'dev', 'prod') type Env = typeof Env[keyof typeof Env] // type '$' | 'dev' | 'prod'
