microsoft / microsoft/TypeScript

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

Aperta
#63,644 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs More Info
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l'esempio Playground collegato e riproducilo usando tsc --noEmit, quindi confronta le build pulite e incrementali mentre modifichi i file che definiscono X; il lavoro è completato quando le ricompilazioni ripetute non producono più TS7053 per questo accesso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
build-system, compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Da chiarire
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.