fix(js-component-bindgen): treat undefined as none when lowering options#1722
Open
GamePad64 wants to merge 1 commit into
Open
fix(js-component-bindgen): treat undefined as none when lowering options#1722GamePad64 wants to merge 1 commit into
undefined as none when lowering options#1722GamePad64 wants to merge 1 commit into
Conversation
vados-cosmonic
approved these changes
Jul 4, 2026
Collaborator
There was a problem hiding this comment.
LGTM 🚀
Thanks for this fix @GamePad64 !
I really think that we should be leaning towards null here other than undefined, but the current type representation documentation it looks like we really do use undefined.
This is probably something left for a breaking change in Jco for the future -- null is an explicit value (that is none-ish) whereas undefined overlaps with a completely missing option, which makes null seem like the better representation here (there are some benefits like when making objects for record values)... That's a conversation for a different time, I guess.
`_lowerFlatOption` mapped only JS `null` to the option `none` case, but jco's own generated TypeScript types model `option<T>` none as `T | undefined`. A value of `undefined` was therefore lowered as `some(undefined)`; when `T` contains an `own<resource>`, `_lowerFlatOwn` then throws `missing resource` and aborts the task.
This surfaced with wasi:http p3 `response.consume-body`, whose trailers future is typed `Result<Trailers | undefined, ErrorCode>`: an empty-trailers `Ok(None)` (`{ tag: 'ok', val: undefined }`) crashed lowering at body completion, leaving the enclosing streaming result's `.next()` unresolved.
Widen the none check to accept `undefined`, consistent with the generated types.
Signed-off-by: Alexander Shishenko <alex@shishenko.com>
2c2dd76 to
f779305
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_lowerFlatOptionmapped only JSnullto the optionnonecase, but jco's own generated TypeScript types modeloption<T>none asT | undefined. A value ofundefinedwas therefore lowered assome(undefined); whenTcontains anown<resource>,_lowerFlatOwnthen throwsmissing resourceand aborts the task.This surfaced with wasi:http p3
response.consume-body, whose trailers future is typedResult<Trailers | undefined, ErrorCode>: an empty-trailersOk(None)({ tag: 'ok', val: undefined }) crashed lowering at body completion, leaving the enclosing streaming result's.next()unresolved.Widen the none check to accept
undefined, consistent with the generated types.