microsoft / microsoft/TypeScript

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

Ouverte
#63,644 9 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Needs More Info
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’exemple Playground lié et reproduisez-le avec tsc --noEmit, puis comparez les builds propres et incrémentiels tout en modifiant les fichiers qui définissent X ; c’est terminé lorsque les rebuilds répétés ne produisent plus TS7053 pour cet accès.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
build-system, compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
À clarifier
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.