From f4b0a2e3228eb9d6d2c8f51e31d250930799ce1d Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 9 Dec 2021 18:48:50 +0800 Subject: [PATCH] fix(cli): enum TypeScript type should be const enum --- cli/src/build.ts | 3 ++- examples/napi/index.d.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/src/build.ts b/cli/src/build.ts index c83f6bfb..869dc5f6 100644 --- a/cli/src/build.ts +++ b/cli/src/build.ts @@ -394,7 +394,8 @@ export class ExternalObject { 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 diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index b46fd4ab..865303f2 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -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 */ @@ -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, @@ -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 }