microsoft / microsoft/TypeScript
experimentalDecorators: a class name used as an object literal key is renamed to the self-reference alias
@RyanCavanaugh ci sta già lavorando.
Dal 15/7/2026.
- #4650 di @copilot-swe-agent — chiusa senza merge
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Version: 7.0.2 (the tsc from the typescript npm package). Emits correctly on 6.x.
With experimentalDecorators on, when a decorated class uses its own name as an object literal property key inside its body, the emitter rewrites the key to the decorator self-reference alias (SessionAuth becomes SessionAuth_1).
Repro
experimentalDecorators: true:
const dec = (t: any) => t;
@dec
class SessionAuth {
static requirement() {
return { SessionAuth: [] };
}
}
Expected emit (what 6.x produces):
static requirement() {
return { SessionAuth: [] };
}
Actual emit on 7.0.2:
var SessionAuth_1;
let SessionAuth = SessionAuth_1 = class SessionAuth {
static requirement() {
return { SessionAuth_1: [] };
}
};
SessionAuth = SessionAuth_1 = __decorate([dec], SessionAuth);
The SessionAuth in the object literal is a property name, not a reference to the class, so it should be left alone. The wrong key only shows up at runtime. In our case it renamed an OpenAPI security scheme key and broke request validation after we upgraded.
The same substitution happens for other name positions that match the class name (a shorthand method name, a class field name). Property access on other objects and string-literal keys are not affected.
Likely a missed instance of a known problem
This looks like the same root cause as microsoft/typescript-go#3146 (enum member access with the same name as a decorated class), which was closed via microsoft/typescript-go#3147. That fix covered the enum-access position; the object-literal-key position seems to have been missed. Might be worth checking whether the fix can be widened to cover all name positions rather than the enum case on its own.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.