Repository navigation
Conversation
…s of
A callback passed to a generic call without a return annotation can
return values the checker unifies into a narrower result type ('return
items' beside 'return items.map((i) => ({ ...i, extra }))' infers
Item[]). Converting the extended objects into that type copied them
and dropped the added members, which Node keeps and a later wider view
reads back. Such a return is now refused by name, pointing at the
annotation that keeps the members.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Comment on lines
+13010
to
+13011
| while (ts.isParenthesizedExpression(site.parent) || ts.isAwaitExpression(site.parent)) | ||
| site = site.parent; |
Contributor
This branch was successfully deployed
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.
The callback here is passed to a generic call and has no return annotation, and its returns extend the elements it was given:
The checker unifies both returns into the narrower
Plain[], sorun'sTisPlain[]. Node keepsextraon the returned objects, and the later wider view reads it back. Natively, converting the extended records into the inferred type was a width copy that droppedextrasilently. On main the last line printed[{"name":"a","n":1},…]where Node prints[{"name":"a","n":1,"extra":true},…].Such a return is now refused by name. The message names the dropped members and points at the fix: an annotation on the callback's return type or on the call's type argument. That annotation names a type that keeps the members, and those programs compile and match Node.
Only conversions the refusal targets change, and gate covers it. A return is refused only when all of these hold:
Callbacks whose results the checker types by their own returns keep every member already, so they are unaffected:
mapwith conditional or spread-extended returns,filter+mapchains, andreducereturning a spread-extended accumulator. All of them were probed and match Node.Evidence
tests/diagnostics/inferred-callback-drops.ts(snapshot) pins the refusal.tests/corpus/6480-generic-callback-extended-results.tscovers the annotated callback, the type-argument form, the async form, and themap/reduceshapes. It is byte-identical to Node in both lanes.pnpm lintandpnpm format:checkare clean,pnpm test:ts7 --baselines-onlypasses, andtests/harness/diagnostics.test.tspasses.🤖 Generated with Claude Code