Skip to content

Commit

Permalink
fix(cli): enum TypeScript type should be const enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 9, 2021
1 parent 0723e15 commit f4b0a2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ export class ExternalObject<T> {
idents.push(def.name)
}
dts +=
indentLines(`${def.js_doc}export enum ${def.name} {`, nest) + '\n'
indentLines(`${def.js_doc}export const enum ${def.name} {`, nest) +
'\n'
dts += indentLines(def.def, nest + 2) + '\n'
dts += indentLines(`}`, nest) + '\n'
break
Expand Down
6 changes: 3 additions & 3 deletions examples/napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Obj {
}
export function either4(input: string | number | boolean | Obj): number
/** default enum values are continuos i32s start from 0 */
export enum Kind {
export const enum Kind {
/** Barks */
Dog = 0,
/** Kills birds */
Expand All @@ -37,7 +37,7 @@ export enum Kind {
Duck = 2
}
/** You could break the step and for an new continuous value. */
export enum CustomNumEnum {
export const enum CustomNumEnum {
One = 1,
Two = 2,
Three = 3,
Expand Down Expand Up @@ -68,7 +68,7 @@ export interface AllOptionalObject {
age?: number | undefined | null
}
export function receiveAllOptionalObject(obj?: AllOptionalObject | undefined | null): void
export enum ALIAS {
export const enum ALIAS {
A = 0,
B = 1
}
Expand Down

0 comments on commit f4b0a2e

Please sign in to comment.