Skip to content

Conversation

mkl-ableton
Copy link

@mkl-ableton mkl-ableton commented Sep 12, 2025

This PR adds an overload of register_type that allows registering type aliases for val-based types. With this, clients can reference a stable, named type without needing to depend on (or update alongside) its underlying definition.

E.g.,

EMSCRIPTEN_DECLARE_VAL_TYPE(MyOwnEnum);

register_type<MyOwnEnum>("MyOwnEnum", "'a' | 'b'");

This addresses the issue raised in #25145.

@FelixNumworks
Copy link

Hi ! I opened a PR to do this in another way, by adding a parameter to enum_<MyEnum>

See #25257

The result in the d.ts file would be

export type MyEnum = 'valueOne'|'valueTwo'|'valueThree'

interface EmbindModule {
  MyEnum: {valueOne: 'valueOne', valueTwo: 'valueTwo', valueThree: 'valueThree'};
};

@FelixNumworks
Copy link

I know it's a bit different as my implementation only works for enums, and not any type, but I think it adresses the problem you raised in your discussion

@mkl-ableton
Copy link
Author

@FelixNumworks Thanks for pointing me to your PR. Exposing enums as strings is exactly my current use case. I hadn’t suggested modifying enum_ myself since I expected it might spark a bigger design discussion. Guess I should’ve just waited a week 🙂. Let’s see when/if your PR lands. I think this one makes sense regardless.

…lias

Introduce a second overload of register_type that creates a named TypeScript
alias for val-based types declared with EMSCRIPTEN_DECLARE_VAL_TYPE.

See changes in tests for examples.
@mkl-ableton mkl-ableton force-pushed the add_overload_of_register_type branch from 6169ec6 to 19614c2 Compare September 12, 2025 17:32
@sbc100 sbc100 requested a review from brendandahl September 15, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants