-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
feat(53461): Implement decorator metadata proposal #54657
Conversation
FYI @rbuckton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add Symbol.metadata
to the libs, probably under lib/esnext.decorators.d.ts
In lib/decorators.d.ts we can make context.metadata
conditional using an approach like this:
// lib.esnext.decorators.d.ts
interface Symbol {
readonly metadata: unique symbol;
}
// lib.decorators.d.ts
...
type DecoratorMetadata = typeof globalThis extends { Symbol: { readonly metadata: symbol } } ? object : object | undefined;
interface ClassDecoratorContext<...> {
...
readonly metadata: DecoratorMetadat;
...
}
...
interface ClassMethodDecoratorContext<...> {
...
readonly metadata: DecoratorMetadat;
...
}
... etc. ...
Ideally, we can take this for the 5.2 beta which has a deadline of this Friday. Let me know if you need me to help with any part of this PR to get it in this week. |
@rbuckton Thank you so much for taking the time to review this PR 👍🏻. I have added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also help to have evaluation tests that run the some of the examples used in the esDecoratorMetadata tests and verify the expected output (see src\testRunner\unittests\evaluation\esDecorators.ts).
To make that work you would need to shim Symbol.metadata
for the evaluation tests, which you can do in src\harness\evaluatorImpl.ts:20. See
https://github.com/microsoft/TypeScript/pull/54505/files?show-viewed-files=true&file-filters%5B%5D=#diff-3b6817a4cdcf825c75e6f9af6cad21356ee6a7cd35bb5d3c92eef8e0985ce910R20-R33 for an example.
…uards to avoid crashes caused by incorrect base prototypes
Some tests are failing and there are merge conflicts. Can you verify baselines and update with main? |
@rbuckton I've merged changes from the |
It looks like one of your evaluation tests is failing. |
@typescript-bot pack this |
Yes. It due to #54657 (comment) |
Hey @rbuckton, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
interface Function {
[Symbol.metadata]?: object | null;
} Sorry, we should add it to src/lib/decorators.d.ts instead, per my other suggestion. |
This is looking fairly close to ready, once the baselines are reviewed and accepted I'll hopefully be able to take a final pass and approve. |
@rbuckton What are your thoughts on moving the following types from interface Function {
[Symbol.metadata]: DecoratorMetadata | null;
} |
It shouldn't be optional since it will already get the |
oke, I've moved it to |
I should have added more detail to this, but it was late. The main reason to not make it an optional property of type FunctionMetadata =
typeof globalThis extends { Symbol: { readonly metadata: symbol } } ? {
[Symbol.metadata]: DecoratorMetadataObject | null;
} : {
[Symbol.metadata]?: DecoratorMetadataObject | null;
};
interface Function extends FunctionMetadata {
} But I think the approach of just using |
Fixes #53461