pmndrs / webidl-dts-gen

Converts Web IDL to Typescript (.d.ts)
10 stars 3 forks source link

Emit correct types for emscripten enums in class namespaces #15

Open isaac-mason opened 1 year ago

isaac-mason commented 1 year ago

https://github.com/emscripten-core/emscripten/blob/dd6774a840872b0902e69cfcb20d553359f52374/tools/webidl_binder.py#L798

regnaio commented 3 months ago

@isaac-mason Thank you for all of your work on this repo

I was wondering if this issue is related to: https://github.com/pmndrs/webidl-dts-gen/blame/main/packages/webidl-dts-gen/src/convert-idl.ts#L546

Nowadays, is it possible in TypeScript to do Module.Enum.MemberName instead of just Module.Enum?

isaac-mason commented 2 months ago

Hey @regnaio, this isn't related no, this tool generates types that match the output of the emscripten webidl binder.

This issue is for emitting correct types for enums under namespaces, e.g. Module.Namespace.MemberName, following current webidl binder behaviour.

For enums to be accessible via Module.Enum.MemberName changes to the webidl binder would be required.

There's a somewhat related issue on the emscripten repo for prefixing enums here: https://github.com/emscripten-core/emscripten/issues/13243

You could comment on that issue or raise another on the emscripten repo if you'd like.

That said, if you'd like to see it happen, you'll probably need to contribute the change yourself :)

For a workaround, see: https://github.com/fabmax/PhysX/pull/1

If you were to do this and still wanted to use webidl-dts-gen to generate types, you'd need to add types for those enums yourself.

regnaio commented 2 months ago

Thank you so much, @isaac-mason , for your links and pointers helping me in the right direction

I feel like you read my mind. Indeed, I was using pmndrs/webidl-dts-gen to generate types for fabmax/physx-js-webidl 😄

I've added a comment to https://github.com/emscripten-core/emscripten/issues/13243

isaac-mason commented 2 months ago

No worries @regnaio! 🙂