microsoft / microsoft/TypeScript

`get self(): this` in an interface crashes the checker (6.0 regression)

未关闭
#63,619 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Fixed
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

getConditionalFlowTypeOfType, getAnnotatedAccessorType, Cannot read properties of undefined (reading 'flags'), accessor this type

### 🕗 Version & Regression Information

- Crashes in 6.0.3 and nightly (6.0.0-dev.20260416); 5.9.3 is clean — a 6.0 regression

### 💻 Code

```ts
interface I {
get self(): this
}
```

### 🙁 Actual behavior

`tsc` crashes:

```
TypeError: Cannot read properties of undefined (reading 'flags')
at getConditionalFlowTypeOfType (typescript/lib/_tsc.js:65892:23)
at getTypeFromTypeNode (typescript/lib/_tsc.js:68622:12)
at getAnnotatedAccessorType (typescript/lib/_tsc.js:62162:20)
at getTypeOfAccessors (typescript/lib/_tsc.js:62180:99)
at checkAccessorDeclarationDiagnostics (typescript/lib/_tsc.js:87089:26)
```

Any `this` nested inside the accessor's return type annotation triggers it too (`get pair(): [this, string]`). A method or property signature with the same `this` type is fine.

### 🙂 Expected behavior

No crash (5.9 checks this without errors).

### Additional information about the issue

_No response_

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用接口片段和报告中的访问器用例重现崩溃。从报告的 checker stack 中的 getAnnotatedAccessorType、getTypeOfAccessors 和 getConditionalFlowTypeOfType 开始,然后定位对应的 TypeScript 源码和回归测试设置。当这些访问器不再崩溃,并且现有的 5.9 行为仍由测试覆盖时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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