microsoft / microsoft/TypeScript

An error occurs when passing the SourceFile node to getTypeAtLocation.

未关闭
#62,190 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Domain: API Needs More Info
主要语言
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.
Image

When executing the isDeclarationNameOrImportPropertyName method, the passed node is still the SourceFile node, and an error is directly reported at name.parent.
Image
Image

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先重现所提供的 ModuleA/ModuleB 示例,并通过 getTypeOfNode、isExternalModule 和 isDeclarationNameOrImportPropertyName 跟踪 getTypeAtLocation。验证传入 SourceFile 节点不再导致 name.parent 错误,并且 getTypeAtLocation 会按预期返回一个类型或 errorType。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。