microsoft / microsoft/TypeScript

Decorator helper `__esDecorate` refers to `Object`, which can be clobbered

Aperta
#61,150 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 12/2/2025.

Needs Investigation
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

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250207#code/PTAEEECcCMEsBdIENIE9QGd5IHYBMBaWHUAMwHtJQB5aAKwFMBjeUWAWwAdL4G8zI5dqADkkAK454qTgwwiAdACgQEHKngALYgHNQ4jLtBbYGUDiTsGoAO7lxAG34ZxpUrCbX45Y5Fg6dBiotayDBSAAuFTAAIlpGFgVA+GobHAAFQVlIaQAROSY-Tm8qU3NyViQySRZYchwY5VUAJQZOByQmIzj6ZngY2wRNUBidB3JoJAcAFW0MBXi+geJjTWsAfXW5fKZKJF5o0AZ2BF5+aHRpmQYAZULYYrJYAA85VetdnFIHD3hlJg6GDMixYoAA3kpQFDQAA3KawPD7BgACgAlBFQNByOQHAxcODIdCiZAGPBxJASKQphgGABuQlQgC+SmZSlINXgdRI4HUOz2JWRVi05DwGNwqAANKBPrxnvAxep0bDyAiCUTPhgcQwFOMdMiRABZUmaEWgPDMfl8ACEIlR9NZAKQQNAADFsWroQABHmoPnIEoMzEoNEYmEq-gQonq+qa3E68h6w3G01MKa4vA2u2B5kOmOsCg+AC85gYNld2LR9ILCkmkErSiAA

💻 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

  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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.