microsoft / microsoft/TypeScript
Diagnostic code 8030 being incorrectly generated using JSDoc `@type` on a function.
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
Diagnostic 8030 is being generated incorrectly when using JSDoc `@type` on a method when the type is being referred to from an interface. This is using the new `tsc` LSP - version 7.0.2.
### 🕗 Version & Regression Information
- This changed between versions 7.0.0-dev.260707.2 and 7.0.2.
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about new native issues being transferred into the main typescript repo.
### ⏯ Playground Link
_No response_
### 💻 Code
```ts
// types.ts
interface Example {
method (): number;
}
export {};
// code.js
const exampleFns = {
/**
* @type {Example['method']} // A JSDoc `@type` tag on a function must have a signature with the correct number of arguments.
*/
method () {
return Math.random();
}
};
```
### 🙁 Actual behavior
in this example, the diagnostic and LSP info does not tell the user that typescript is internally suffixing `| undefined` to the type. As such wrapping the type in `NonNullable` removes the error diagnostic, I do not believe this to be intended behaviour as previous iterations the golang native LSP `tsgo` (7.0.0-dev.260707.2) did not produce this diagnostic, nor did previous versions of typescript.
### 🙂 Expected behavior
The type should be properly referenced with no additional suffixing of types, as it used to.
### Additional information about the issue
_No response_
贡献指南
调研方向
首先,使用报告的 TypeScript 7.0.2 和更早的 7.0.0-dev.260707.2 版本,通过 types.ts 和 code.js 重现该诊断。跟踪对 Example['method'] 的 JSDoc @type 引用是如何解析的,以及为什么会添加 | undefined。完成的标准是:有效的方法类型不再产生诊断 8030,并且此示例具有回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100