diff --git a/.changeset/chatty-eyes-bow.md b/.changeset/chatty-eyes-bow.md new file mode 100644 index 0000000..8f7c171 --- /dev/null +++ b/.changeset/chatty-eyes-bow.md @@ -0,0 +1,5 @@ +--- +"webidl-dts-gen": minor +--- + +fix: emscripten enum values should be numbers diff --git a/packages/webidl-dts-gen/src/convert-idl.ts b/packages/webidl-dts-gen/src/convert-idl.ts index c2b5a4f..18f8ee2 100644 --- a/packages/webidl-dts-gen/src/convert-idl.ts +++ b/packages/webidl-dts-gen/src/convert-idl.ts @@ -549,7 +549,7 @@ function convertEnum(idl: webidl2.EnumType, options: Options, emscriptenEnumMemb const variableDeclaration = ts.factory.createVariableDeclaration( ts.factory.createIdentifier(member), undefined, - ts.factory.createTypeReferenceNode('any', undefined), + ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), ) return ts.factory.createVariableStatement( diff --git a/packages/webidl-dts-gen/tst/index.spec.ts b/packages/webidl-dts-gen/tst/index.spec.ts index a77f7fd..5aed0e3 100644 --- a/packages/webidl-dts-gen/tst/index.spec.ts +++ b/packages/webidl-dts-gen/tst/index.spec.ts @@ -137,8 +137,8 @@ describe('convert', () => { expect(ts).toBe( withDefaultEmscriptenOutput( - 'const bar: any;', // - 'const baz: any;', // + 'const bar: number;', // + 'const baz: number;', // 'type Foo = typeof bar | typeof baz;', // 'function _emscripten_enum_Foo_bar(): Foo;', // 'function _emscripten_enum_Foo_baz(): Foo;', // @@ -158,8 +158,8 @@ describe('convert', () => { expect(ts).toBe( withDefaultEmscriptenOutput( - 'const bar: any;', // - 'const baz: any;', // + 'const bar: number;', // + 'const baz: number;', // 'type Foo = typeof bar | typeof baz;', // 'function _emscripten_enum_Foo_bar(): Foo;', // 'function _emscripten_enum_Foo_baz(): Foo;', //