-
Notifications
You must be signed in to change notification settings - Fork 64
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
Transpile bindings for u32
map to number
in *.d.ts
#402
Comments
U32 lowering does coercion currently - https://github.com/bytecodealliance/jco/blob/main/crates/js-component-bindgen/src/function_bindgen.rs#L260. We could possibly move to validation with traps for all user-provided values. |
Curious, IIUC the intent here is to ensure no negative numbers should be possible, yet in my example above,at runtime we happily underflow with a negative number passed in... Should that trap? I would be a strong advocate for the behavior to try and do its best to fail at runtime if wit import / export type properties are violated (by default at least). As it is now, devs need to make those assertions wrapping the bindings in JS, correct? |
Yes, currently the trap behaviour is inconsistent, some type errors trap and others coerce. |
This inconsistency lead to a somewhat unexpected behavior in my code. I totally agree with @nuke-web3 when they state "I would be a strong advocate for the behavior to try and do its best to fail at runtime if wit import / export type properties are violated (by default at least)." Shouldn't the behavior be at least as strict as the generated TypeScript types require it? Is there a plan to change this. |
I noticed in making this little demo that I could not use signed or out-of-bounds numbers for
wasmtime
but that in the browser and via node it does.https://stackoverflow.com/help/minimal-reproducible-example adding to the cli:
../wit/calculator.wit
jco
version 1.0.3 generatedbindings/interfaces/docs-calculator-calculate.d.ts
cli-calc.js:
Is there a way now to ensure that bindings generated use the WIT specified stronger types? I would think softening the interface to
number
should not be the default 😅The text was updated successfully, but these errors were encountered: