microsoft / microsoft/TypeScript
An error occurs when passing the SourceFile node to getTypeAtLocation.
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 Search Terms
getTypeAtLocation && SourceFile
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
No response
💻 Code
//ModuleA
export let namedOther = null;
//ModuleB
import * as testNs from './ModuleA';
export { testNs };
🙁 Actual behavior
In the statement 'export { testNs }', call getTypeAtLocation on 'testNs' to retrieve its type.
🙂 Expected behavior
It is expected to obtain the returned type, whether the result is errorType or another type, but in reality, an error 'Cannot read properties of undefined (reading 'kind')' will be reported in getTypeAtLocation#getTypeOfNode#isDeclarationNameOrImportPropertyName.
Additional information about the issue
The getTypeOfNode function supports passing a SourceFile node, but if the condition isExternalModule is not met, the SourceFile node will proceed to execute further.
When executing the isDeclarationNameOrImportPropertyName method, the passed node is still the SourceFile node, and an error is directly reported at name.parent.
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先重现所提供的 ModuleA/ModuleB 示例,并通过 getTypeOfNode、isExternalModule 和 isDeclarationNameOrImportPropertyName 跟踪 getTypeAtLocation。验证传入 SourceFile 节点不再导致 name.parent 错误,并且 getTypeAtLocation 会按预期返回一个类型或 errorType。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100