TypeScript: a local initialized from a library call takes the one-method guess (follow-up to #2589)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, react, typescript
- 领域
- devtools
调研方向
Reproduce the five functions from the issue in a TypeScript fixture and run the resolver with CODEGRAPH_KERNEL=0, then trace where a local initialized from an outside-project call is assigned the single same-named project method. Compare that path with the annotated-local handling from #2589/#2811 and the outside-type rule in #2169; the fix belongs there, not in variable-name heuristics. Done means a-d emit no instance-method edge while existing project-local cases still resolve, with coverage for package imports, node: namespaces and DOM-typed receivers.
由索引模型根据 Issue 内容生成。
描述
Follow-up to #2589. A method call on an untyped local initialized from a library call still links to the project's only method with that name. #2811 fixed this for a class component's render() and lifecycle methods, but an ordinary class method is still guessed.
// app.ts
export class App { render(): void {} translate(x: number): void {} close(): void {} }
// use.ts
import { createRoot } from 'react-dom/client';
import * as net from 'net';
import { createServer } from 'net';
export function a(el: HTMLElement) { const root = createRoot(el); root.render(null); }
export function b() { const s = net.createServer(); s.close(); }
export function c() { const s = createServer(); s.close(); }
export function d(canvas: HTMLCanvasElement) { const ctx = canvas.getContext('2d')!; ctx.translate(1); }
export function e(canvas: HTMLCanvasElement) { canvas.getContext('2d')!.translate(1); }
| function | edge on main |
expected |
|---|---|---|
a |
App.render (instance-method) |
none |
b |
App.close |
none |
c |
App.close |
none |
d |
App.translate |
none |
e (chained, no local) |
none | none |
Renaming the locals doesn't change anything, so this isn't the variable-name guess in #2946. The chained form e already links nothing; only the assigned local takes the guess. In each case the local's value comes from something the project doesn't declare: a package import, a node: namespace, or a method on a DOM-typed parameter. That fits #2169's "an outside type is not a project type" rule, but the type is never written down, so the rule doesn't fire.
Reproduced on main at 31ec9082 (6162d872 since then only touches the watcher), with CODEGRAPH_KERNEL=0. Linux/WSL2, Node 22.23.2.
Scale (found by checking every TS calls edge against the TypeScript checker). On excalidraw (14bb42e), 63 instance-method edges land on project code where tsc says the method is a library one. For example, every context.translate(…) on a canvas.getContext("2d")! local, as in packages/element/src/renderElement.ts, links to App.translate in packages/excalidraw/components/App.viewport.ts. On this repo there are 58. For example, server.close() on net.createServer(…) in __tests__/cli-unlock.test.ts links to the close() of the viewer's server interface in src/ui-server/index.ts. The interface method gets callers it never has.
Possible direction (not verified). When the local's initializer is a call whose callee resolves outside the project (an import from a package or node:, or a member of a receiver already typed as an outside type), treat the local as outside-typed: the same "no guess" outcome as an annotated const r: Root = createRoot(el) in #2589. #2152 has PHP's version of this ("an untyped receiver keeps a unique method only when named for it").
Related: #2589, #2811, #2169, #2946.
- 主要语言
- C
- 星标
- 73.2k
- 派生
- 4.7k
- 平均合并
- 3 小时 13 分钟
- 30 天内合并 PR
- 579
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
colbymchenry/codegraph 的其他 Issue
-
mcp: a projectPath naming a file inside a project returns isError ("Path is not a directory")可能已有人在做 @maxmilian 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
colbymchenry/codegraph#2982 ·
维护者通常 1 天内回复
-
mcp: a non-object tools/call arguments crashes the handler and is reported as an internal error to retry可能已有人在做 @kjgggggg 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
colbymchenry/codegraph#2981 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
colbymchenry/codegraph#2974 ·
维护者通常 1 天内回复
-
search: FTS special characters are deleted, not separated, so leaf(entry) matches nothing可能已有人在做 @kjgggggg 于 1 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
colbymchenry/codegraph#2971 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
colbymchenry/codegraph#2959 · 1 条评论 ·
维护者通常 1 天内回复
查看 colbymchenry/codegraph 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
InukaAsith/TwinDesk#84 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
CanadaHonk/porffor#426 ·
-
难度 1/5 1 小时以内 新手友好度 77/100
raysan5/raylib.com#132 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 76/100