Skip to content

fix(ts): a local's call result and an interface's property decide its method, not a guess - #3371

Merged
colbymchenry merged 1 commit into
mainfrom
claude/issue-2947-ts-outside-locals
Nov 18, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/issue-2947-ts-outside-locals

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Summary

A TS/JS method call on a receiver nothing types falls to the guess by the method's name: the one project method of that name, or one whose class the receiver's words name. Three receivers the resolver can now read better:

Root cause

Fix (src/resolution/name-matcher.ts)

  • tsValueType: Class.method(…), with nothing in scope binding the class's name, reads as the return type of the class's one static method of that name (tsStaticReturnedType). The method must be written once and not generic, and its return type must be one type, not this and not a type parameter of the class. The declaration pattern the readers pre-filter with now admits any member-call initializer.

  • jsOutsideValueBinding / jsOutsideCallValue: a const/let with no type written, initialized by one of these calls, links nothing:

    • a function or module member the file imports from a declared package or Node;
    • a method of a parameter typed by a type no project file declares, written with no type arguments.

    A call handed a project declaration by name stays as before, since it may hand it back: TestBed.inject(Service), accessor.get(IEditorService), useContext(StoreContext). So does a hook given a callback (useMemo(() => new Store(), [])).

  • tsPropertyOwner + strategy 3: when the receiver's declared type, or a type up its chain, has a property of the method's name, the guess is made only among classes that extend or implement that type, or whose file names it. Excalidraw's Collab builds its CollabAPI object out of its own methods. A lone subtype still answers alone, which keeps bitwarden's AuthService extends AuthServiceAbstraction case. A class that only names the type doesn't get the one-method shortcut when others were ruled out.

  • A local cast where it is declared, const matcher = fn as Matcher;, is read as that type (jsCastLocalReading).

Validation

  • New __tests__/ts-call-result-receivers.test.ts, 6 cases: 3 fail on main and pass now (the four library-call locals; the static factory under two local names; the function-typed property through a cast and through a parameter). 3 guards pass on both: a project function's result; a subclass of an abstraction with a function-typed property, the bitwarden shape; a class building the interface from its own methods.

  • A/B against the 1.6.3 source (147fe290), both arms on the same 1.6.3 kernel. Every changed call site was checked against a whole-program TypeScript checker (go-to-definition, overloads read at their implementation):

    repo added retargeted confidence-only removed
    vscode src/vs/base + src/vs/editor (1,871 files) 167, static factories (URI.file/URI.parse locals ×74, VSBuffer.* ×34, Random.create ×13, TokenTheme.create* ×12, …) 2 152 66
    codegraph's own src/ + 4 tests 6 3 (writer = DatabaseConnection.initialize(…) in concurrent-locking.test.ts, the issue's example) 15 17
    excalidraw (d3a9c2a1) 0 0 3 1 (a tinycolor(…) result's getFormat)
    flask, gin (controls) byte-identical
    • vscode: every added, retargeted and confidence-changed site goes where the checker goes. 8 are VSBuffer.set, overloaded, which codegraph places at its first signature. Of the 66 removed, 46 sit on values from outside the project. The other 20 linked an unrelated class's method where the checker names a property or event of the declared type (options.equals → MinimapOptions.equals, model.onDidCancel → ActionBar.onDidCancel, …).
    • codegraph: of the 17 removed, server.close() ×2 sits on net.createServer and http.createServer results (the TypeScript: a local initialized from a library call takes the one-method guess (follow-up to #2589) #2947 example). The other 15 go through function-typed properties: job.resolve → FrameworkResolver.resolve, and deps.warn/deps.error → Logger, where UpgradeDeps.warn is a lambda around a local warn().
  • Index cost on excalidraw (median of 3, interleaved, CPU time of all threads): 32.0 s → 32.3 s, within noise.

  • Its own test file plus the 105 TS/JS resolution test files on this commit: 106 files, 1,334 passed, 1 skipped, 1 timed out (function-ref.test.ts Caller/impact graph misses methods passed as first-class references (callbacks), e.g. executor.submit(obj.method, …) #1820, a Python case with its own 60 s limit, a known load flake; that file alone: 36 passed). Full suite: on the combination of this group's PRs, reported when it finishes.

Left out

Fixes #2947
Fixes #2946
Fixes #3035

🤖 Generated with Claude Code

@colbymchenry
colbymchenry force-pushed the claude/issue-2947-ts-outside-locals branch from 8b9a578 to 68a510b Compare November 18, 2026 00:16
… method, not a guess

A TS/JS method call on a receiver nothing types falls to the guess by the
method's name: the one project method of the name, or one whose class the
receiver's words name. Three receivers the resolver can read better.

Issue 2946: a local a static factory initializes, `const writer =
DatabaseConnection.initialize(p)`, held nothing the readers read, so
`writer.close()` took StoreWriter's close by the variable's name. The
call-result reader (#3319) now reads `Class.method(…)` as the class's one
static method of the name says it returns (tsStaticReturnedType: written
once, not generic, one type, not `this` or a type parameter of the class),
with nothing in scope binding the class's name.

Issue 2947: a local a library call initializes, `createRoot(el)` from
react-dom, `net.createServer()`, `canvas.getContext('2d')!` on an
HTMLCanvasElement parameter, holds the library's value, but took the one
project method of the name (App.render, App.translate). Such a local
(jsOutsideValueBinding: a function or module member the file imports from a
declared package or Node, or a method of a parameter typed by a type no
project file declares, written with no type arguments) now links nothing.
A call handed a project declaration by name (`TestBed.inject(Service)`,
`accessor.get(IEditorService)`, `useContext(StoreContext)`) or a hook given
a callback (`useMemo(() => new Store(), [])`) may hand it back, and reads as
before.

Issue 3035: a receiver typed by an interface whose member of the name is a
function-typed property (`snapshot?: () => …`) left tsMethodUpChain
incomplete, and the guess took an unrelated class's method of the name. The
guess is now made among the classes that extend or implement that type, or
whose file names it (excalidraw's Collab builds its CollabAPI object out of
its own methods); a lone subtype still answers, so bitwarden's abstract
function-typed properties keep their implementations. A local cast where it
is declared (`const matcher = fn as Matcher;`) is read as that type.

Validation:
- New ts-call-result-receivers.test.ts, 6 cases: 3 fail on main (the four
  library-call locals; the static factory with two local names; the
  function-typed property through a cast and a parameter) and pass now; 3
  guards pass on both (a project function's result, a subclass of an
  abstraction with a function-typed property, a class building the
  interface from its methods).
- A/B against the 1.6.3 source, both arms on the 1.6.3 kernel, every
  changed call site checked with a whole-program TypeScript checker:
  - vscode src/vs/base + editor: 167 added (static factories: URI.file and
    URI.parse locals' toString/with, VSBuffer, Random.create,
    TokenTheme.create*, …), 2 retargeted, 152 confidence-only, all where the
    checker goes (8 of them VSBuffer.set, overloaded, read at its first
    signature); 66 removed, 46 on values from outside the project and 20
    whose old target was an unrelated method while the checker names a
    property or event of the declared type.
  - codegraph's own src plus 4 tests: 6 added and 3 retargeted (writer =
    DatabaseConnection.initialize(...) in concurrent-locking.test.ts, the
    issue's example), 15 confidence-only, 17 removed (net and http
    createServer results' close, ParseJob's resolve and UpgradeDeps' warn and
    error properties), all right by the checker.
  - excalidraw: 1 removed (a tinycolor result's getFormat), 3
    confidence-only.
  - flask and gin: byte-identical.
- Index cost on excalidraw (median of 3, interleaved, CPU of all threads):
  32.0 s -> 32.3 s, within noise.

Fixes #2947
Fixes #2946
Fixes #3035

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant