Skip to content

fix(ts): type parameters of const-typed arrow functions (#3443) - #3511

Closed
inth3shadows wants to merge 3 commits into
colbymchenry:mainfrom
inth3shadows:fix/3443-callback-typed-param
Closed

inth3shadows wants to merge 3 commits into
colbymchenry:mainfrom
inth3shadows:fix/3443-callback-typed-param

Conversation

@inth3shadows

Copy link
Copy Markdown
Contributor

Part of #3443 (companion to #3500)

Draft — in progress: Targeted tests, Round-2 broad review fixes, and fixture checks are in place; full test suite, updated corpus measurement on v1.6.5, and final adversarial verification review are still in progress before marking ready for review.

What

In TypeScript, an arrow function or function expression assigned to a const/let/var written with a function type — like const onChange: OnChange = ({ scene }) => { scene.mutateElement(...); } or const 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 .tsx lone-method guesses on excalidraw, while this branch restores the positive typed links for the 16 Stats/* callback-typed arrows (DragInputCallbackType) and turns the issue-3443 fixture from CHANGED to FIXED.

How

  • jsTypedArrowParameterReading (called after jsCallbackParameterReading in jsReceiverReadElsewhere) checks whether a parameter or destructured property belongs to a function assigned to a typed const/let/var declarator (jsTypedConstType).
  • For a named alias (generic or non-generic, local or imported), tsTypeAliasNamed and tsAliasValueText read the alias body in its declaring file (blanking string and template literal types, recording cross-file reads for incremental sync, and rejecting the alias's own type parameters).
  • Leading this parameters 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 aedff9ab7 vs this branch 9be8f9df, Node 22, Linux x64, CODEGRAPH_KERNEL=0)

  • New tests (__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.
  • Full test suite on the v1.6.5-rebased head and refreshed excalidraw corpus measurement: pending final verification pass before marking ready (earlier pre-rebase run on 17a51f77 measured 15 wrong removed, 48 right added, 0 wrong added on excalidraw).
  • Compatibility: re-index TypeScript projects after upgrading; no schema or CLI change.

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-3443

Known limits

  • Destructured parameters are read only when the function type writes the parameter's object type in place ((props: { scene: Scene }) => void), not through a named interface ((props: Props) => void), renamed properties, or defaults.
  • Remaining excalidraw #3443 shapes outside this PR's scope: object-literal contextual typing (actionFinalize) and useCallback closures (ElementLinkDialog, Hyperlink).
  • Final adversarial verification review and full-suite run on 9be8f9df will be recorded before marking ready.

…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.
@inth3shadows

Copy link
Copy Markdown
Contributor Author

Superseded by #3524 (which covers #3443 directly). Closing this draft; left a few edge-case notes on #3524.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant