You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A TypeScript custom transformer which enables enumerating members of the union of string literal types.
Requirement
TypeScript >= 2.4.1
How to use this package
This package exports 2 functions.
One is enumerate which is used in TypeScript codes to enumerate members of the union of string literal types, while the other is a TypeScript custom transformer which is used to compile the enumerate function correctly.
Unfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (See microsoft/TypeScript#14419 for detail).
It is recommended to use the custom transformer with webpack, Rollup, or ttypescript as described.
You can also use the transformer with TypeScript compiler API as follows.
constts=require('typescript');constenumerateTransformer=require('ts-transformer-enumerate/transformer').default;constprogram=ts.createProgram([/* your files to compile */],{strict: true,noEmitOnError: true,target: ts.ScriptTarget.ES5});consttransformers={before: [enumerateTransformer(program)],after: []};const{ emitSkipped, diagnostics }=program.emit(undefined,undefined,undefined,false,transformers);if(emitSkipped){thrownewError(diagnostics.map(diagnostic=>diagnostic.messageText).join('\n'));}
As a result, the TypeScript code shown above is compiled into the following JavaScript.