Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to stage 3 #14

Open
pabloalmunia opened this issue May 8, 2023 · 1 comment
Open

Support to stage 3 #14

pabloalmunia opened this issue May 8, 2023 · 1 comment

Comments

@pabloalmunia
Copy link

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.

@transitive-bullshit
Copy link

transitive-bullshit commented May 29, 2024

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:

  1. Why is this proposal separate from the core decorators proposal given that they overlap so much and from what I can tell, many of the MVP use cases for decorators require metadata to work? Is it because decorators were already such a complicated feature that it was more practical to split them up?
  2. What is the status of this decorator metadata proposal?

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! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants