microsoft / microsoft/TypeScript
Decorator helper `__esDecorate` refers to `Object`, which can be clobbered
@rbuckton ci sta già lavorando.
Dal 12/2/2025.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
🔎 Search Terms
__esDecorate decorator clobber object global
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about decorators
⏯ Playground Link
💻 Code
// Arbitrary stand-in for Object imported from 'runtypes'.
// Anything using this name would suffice to trigger the error:
// "Object.getOwnPropertyDescriptor is not a function".
// Replacing "Object" with "globalThis.Object" in the __esDecorate
// emitted by TypeScript fixes the conflict.
class Object {
validate(): boolean {
return false;
}
}
function AnyDecorator(method: any, context: any): void {
console.log('Method decorated!');
}
class Foo {
@AnyDecorator
bar(): void {
console.log('Method called!');
}
}
const foo = new Foo();
foo.bar();
🙁 Actual behavior
TypeScript emits the decorator helper __esDecorate, which refers to Object. This is clobbered by an Object class defined in or imported by the module, which leads to the error Object.getOwnPropertyDescriptor is not a function at runtime.
🙂 Expected behavior
__esDecorate should use globalThis.Object to avoid this naming conflict. I've confirmed that modifying the compiler output to use globalThis.Object instead of plain Object fixes the conflict.
Additional information about the issue
This was discovered when I used decorators with the runtypes library, which exports a class called Object, used for validating object structures at runtime. The two don't even have to be used together in any meaningful way. They just have to be referenced in the same module.
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.