Repository navigation
fix(ts): a local's call result and an interface's property decide its method, not a guess - #3371
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-2947-ts-outside-locals
branch
from
November 18, 2026 00:16
8b9a578 to
68a510b
Compare
… 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>
colbymchenry
force-pushed
the
claude/issue-2947-ts-outside-locals
branch
from
November 18, 2026 02:46
68a510b to
bc26c21
Compare
This was referenced Nov 18, 2026
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.
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:
const writer = DatabaseConnection.initialize(p), now holds what the factory says it returns.writer.close()linksDatabaseConnection.closeinstead ofStoreWriter.close, which was picked by the variable's name.createRoot(el)from react-dom,net.createServer(),createServer()fromnet, andcanvas.getContext('2d')!on anHTMLCanvasElement. Such a local no longer takes the one project method of the name (App.render,App.close,App.translate).matcher.snapshot(), no longer links an unrelated class'ssnapshot. A class that implements the interface, or builds it, still links.Root cause
Class.factory(…)was explicitly left as before.tsMethodUpChaintreats a same-named property as "incomplete" (fix(ts): a call on a known class goes through that class's own bases #2656, kept for bitwarden's abstract function-typed properties), so the guess ran over every class in the project.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, notthisand not a type parameter of the class. The declaration pattern the readers pre-filter with now admits any member-call initializer.jsOutsideValueBinding/jsOutsideCallValue: aconst/letwith no type written, initialized by one of these calls, links nothing: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'sCollabbuilds itsCollabAPIobject out of its own methods. A lone subtype still answers alone, which keeps bitwarden'sAuthService extends AuthServiceAbstractioncase. 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):src/vs/base+src/vs/editor(1,871 files)URI.file/URI.parselocals ×74,VSBuffer.*×34,Random.create×13,TokenTheme.create*×12, …)src/+ 4 testswriter = DatabaseConnection.initialize(…)inconcurrent-locking.test.ts, the issue's example)d3a9c2a1)tinycolor(…)result'sgetFormat)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, …).server.close()×2 sits onnet.createServerandhttp.createServerresults (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, anddeps.warn/deps.error→Logger, whereUpgradeDeps.warnis a lambda around a localwarn().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.tsCaller/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
package.json(a bare fixture) isn't known to be outside, so a local from it keeps today's guess. This matches every other outside-package rule in the resolver; TypeScript: an import from a package not in package.json links an unimported project export of the same name #3271 is about that.useMemo(() => …)) keeps today's guess either way.stream: { onAbort(…): void }) keeps the one-method guess. Ruling out every object-typed parameter lost right edges in the A/B, such asprintFileTree'schalkand the extractors'ctx, which callers pass real objects.Fixes #2947
Fixes #2946
Fixes #3035
🤖 Generated with Claude Code