Make typings more specific #100
Copy link
Copy link
Open
Description
Hello! Currently, binaryen.d.ts contains definitions that don't allow TypeScript compiler to properly narrow down ExpressionInfo. It would be nice to have more specific typings. I suggest the following changes:
- Change type of Id exports to match the corresponding enum value.
- Change the
ExpressionInfointerface to a union type with the corresponding ids.
Should I make a PR or is this behaviour intentional?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
chharvey commentedon Oct 2, 2025
I agree with this so hard I was about to start my own PR to implement it. But a community effort would be great!
It would solve problems like this:
Currently, everything is just type
number, so TypeScript doesn’t see a problem with the code above. This compiles, but returns an invalid WASM module at runtime.What we want is a “nominal” type system, where types are only assignable by name rather than by their shape — we want some
numbers to not be assignable to others. TypeScript can’t do that, but we can fake it using type intersections. This example can be fixed by redefiningExpressionRefas a generic type returning an intersection with an ad hoc object type.Then the code is updated: