-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[embind] Add register_type<T>(name, definition) #25272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[embind] Add register_type<T>(name, definition) #25272
Conversation
Hi ! I opened a PR to do this in another way, by adding a parameter to 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'};
}; |
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 |
@FelixNumworks Thanks for pointing me to your PR. Exposing enums as strings is exactly my current use case. I hadn’t suggested modifying |
6169ec6
to
19614c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you push an update and i'll merge once tests run?
register_type<CallbackType>("(message: string) => void"); | ||
// Named alias form (emits: type Callback = (message: string) => void;) | ||
// register_type<CallbackType>("Callback", "(message: string) => void"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// register_type<CallbackType>("Callback", "(message: string) => void"); | |
register_type<CallbackType>("Callback", "(message: string) => void"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included that suggestion in 1deebdf
19614c2
to
c2469c3
Compare
…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.
c2469c3
to
1deebdf
Compare
@brendandahl Thanks for the review. I rebased on |
This PR adds an overload of
register_type
that allows registering type aliases forval
-based types. With this, clients can reference a stable, named type without needing to depend on (or update alongside) its underlying definition.E.g.,
This addresses the issue raised in #25145.