Repository navigation
fix(ts): type parameters of const-typed arrow functions (#3443) - #3511
Closed
inth3shadows wants to merge 3 commits into
Closed
inth3shadows wants to merge 3 commits into
inth3shadows wants to merge 3 commits into
Conversation
…ters that type
`const onChange: OnChange = ({ scene }) => { scene.mutateElement(...) }`
with `type OnChange = (props: { scene: Scene }) => void` left `scene`
untyped, so the call was linked by name (on excalidraw, 16 calls in
the Stats components went to App.mutateElement through the generic
DragInputCallbackType alias). The parameter, or a property of a
destructured parameter, now takes the type the const's function type
declares at its position: an alias the file declares or imports, read
in the alias's file, or a function type written in place. A property
typed by the alias's own type parameter reads as nothing.
Refs 3443.
…r, reads whole members (review G1-G8)
…omments and template types (review N1-N6)
Contributor
Author
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.
Part of #3443 (companion to #3500)
What
In TypeScript, an arrow function or function expression assigned to a
const/let/varwritten with a function type — likeconst onChange: OnChange = ({ scene }) => { scene.mutateElement(...); }orconst onScene: OnScene = (scene) => { scene.mutateElement(...); }— now gives its untyped parameters (and properties of a destructured parameter when the function type writes its object type in place) the types declared at their position in that function type. Calls on those parameters link to the declared class's method (Scene::mutateElement) instead of falling through to by-name matching.This complements #3500: #3500 removes the 27 wrong
.tsxlone-method guesses on excalidraw, while this branch restores the positive typed links for the 16Stats/*callback-typed arrows (DragInputCallbackType) and turns theissue-3443fixture fromCHANGEDtoFIXED.How
jsTypedArrowParameterReading(called afterjsCallbackParameterReadinginjsReceiverReadElsewhere) checks whether a parameter or destructured property belongs to a function assigned to a typedconst/let/vardeclarator (jsTypedConstType).tsTypeAliasNamedandtsAliasValueTextread the alias body in its declaring file (blanking string and template literal types, recording cross-file reads for incrementalsync, and rejecting the alias's own type parameters).thisparameters are skipped on both sides, rest parameters stop positional matching, unbalanced generic union/intersection types are rejected, and semicolon-free prior declarations do not leak across statements.Measured (base
aedff9ab7vs this branch9be8f9df, Node 22, Linux x64,CODEGRAPH_KERNEL=0)__tests__/ts-callback-typed-arrow.test.ts): 10/10 pass on this branch; on base (3c230869/aedff9ab7) the initial bug cases fail and the annotated control passes.tsc --noEmit: exit 0;npm run build: exit 0.17a51f77measured 15 wrong removed, 48 right added, 0 wrong added on excalidraw).Checked with graph-assay
I maintain graph-assay. Its issue-3443 fixture goes from BROKEN on
main(aedff9ab7) to FIXED on this branch (9be8f9df). No other fixture verdict changed.Rerun:
node bin/graph-assay replay <codegraph build>/dist/bin/codegraph.js issue-3443Known limits
(props: { scene: Scene }) => void), not through a named interface ((props: Props) => void), renamed properties, or defaults.#3443shapes outside this PR's scope: object-literal contextual typing (actionFinalize) anduseCallbackclosures (ElementLinkDialog,Hyperlink).9be8f9dfwill be recorded before marking ready.