Open pabloalmunia opened 1 year ago
Adding some context for fellow decorator explorers 😄
TypeScript added support for decorator metadata in this PR which is described in their 5.2 release notes.
esbuild has also added support for this proposal here.
Can anyone from tc39 provide clarity on a few questions here:
This comment from the TS discussion tracking decorator metadata by @EisenbergEffect would seem to imply that the decorator metadata proposal is stage 3 alongside decorators, but I'm not sure the extent to which that's talking about decorators vs decorator metadata.
btw I'm currently using the following polyfill for decorator metadata:
// https://github.com/microsoft/TypeScript/issues/53461
// symbol-polyfill.ts
declare global {
interface SymbolConstructor {
readonly metadata: unique symbol
}
}
;(Symbol as any).metadata ??= Symbol.for('Symbol.metadata')
const _metadata = Object.create(null)
if (typeof Symbol === 'function' && Symbol.metadata) {
Object.defineProperty(globalThis, Symbol.metadata, {
enumerable: true,
configurable: true,
writable: true,
value: _metadata
})
}
Thanks! 🙏
It's important the next TC39 meeting session about Decorator Metadata for Stage 3 (slides, spec). We need the decorator metadata because, without it, we have limited the decorator feature.
Especially important is - at least for some teams - to be able to coordinate decorators with metadata, especially the class member decorators, which in this current pattern as mere metadata annotators, and the associated class decorator, which reads from the metadata and performs the necessary transformations and adaptations.
As a workaround, when we use "method", "getter", "setter" or "accessor" decorators, we can put a symbol in each function to put metadata there, but with "field" we don't have a shelf where to put metadata.
Of course, without this feature, work with metadata and inheritance is very complicated.
Consequently, we need the decorator metadata as soon as possible.