microsoft / microsoft/TypeScript

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

Open
#63,644 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs More Info
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground example and reproduce it using tsc --noEmit, then compare clean and incremental builds while changing the files that define X. Inspect how incremental cache state handles the unique symbol property and declaration merging; done means repeated rebuilds no longer produce TS7053 for this access.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.