microsoft / microsoft/TypeScript

In a class, an unique symbol attribute is sometime lost during incremental build

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

还没有人认领这个 Issue。

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

描述

### 🔎 Search Terms

- unique property
- incremental build
- interface declaration merging

### 🕗 Version & Regression Information

- Tested with 6.0.2 and 6.0.3

### ⏯ Playground Link

[Playground Link](https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260416#code/MYewdgzgLgBAygTQLICEDyAZAXDArmASwEdcBTGCATwFsAjEAGxgF54b6GAKASgG4AofsAYBDCBBgANGAG9BMBTAAOAJxBRSwDQBMYIqFBUsYAIhABrEwP6KYK0iO3gGlGAG1EqTAF1jZy9a2quqaOjAAZiAgPLI2tooA9Al4EOQEUHHxMFAAFgQQHsjoGN4CtgC+-JX8UJRK5AAqADwAcjCkAB4aYNoS0CoEYADmAHzGAEqaICraTQAGjtoAJDIt5XMANDAxzGMAbiAE2iPWgxoq4SLA5NKd3b0wzSY5IMAmYzLVoJCwHcafegkkgEHQAdIsXsAgA)

### 💻 Code

I do not have a minimal reproductible exemple as the issue seems to come from the incremental build.

I had a class with an unique symbol property, on which I was doing interface declaration merging:
```ts
const SYMBOL: unique symbol = Symbol();

class X {

protected attr = "ok";

readonly [SYMBOL] = "ok";

protected foo() {
// use it
this[SYMBOL];
}
}

type T = Record<`add${N}`, () => void>;

interface X extends T<"hoc"> {}

const x = {} as X;
x.addhoc
```

### 🙁 Actual behavior

The following error first appeared when I set some of the public attributes as protected (the error below is edited to match the provided exemple) :
```
ERROR in [...]
TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'X'.
Property '[????.SYMBOL]' does not exist on type 'X'.
92 |
93 | protected foo() {
> 94 | this[SYMBOL];
| ^^^^^^^^^^^^^^^^
95 | }
```

I noticed that :
- The error disappear if I delete all of TS cache files.
- The error reappear if I rebuild without any changes to the files.
- The error reappear if I edit the files that defines `X`.
- The error does not reappear if I change other files.
- In watch mode, the error sometimes disappear and reappear when I change the files that defines `X`.
- The error doesn't appear in my VSC editor.

### 🙂 Expected behavior

No TS errors.

### Additional information about the issue

I also reproduced the error with `tsc --noEmit`, so it doesn't seem to come from my Webpack build system.

贡献指南

打开贡献指南

从这里开始

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

调研方向

从链接的 Playground 示例开始,使用 tsc --noEmit 重现该示例,然后在修改定义 X 的文件时比较干净构建和增量构建;当重复重建不再为此访问生成 TS7053 时,即表示完成。

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

评估

技术栈
typescript
领域
build-system, compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
需要澄清
新手友好度
45/100

把新 issue 发到你的邮箱

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