Open paulsmithkc opened 11 months ago
AFAIU this is not implemented yet. See https://github.com/microsoft/TypeScript/issues/53461.
Same problem. Lots of libraries use metadata about types, such as Angular, NestJs, class-validator, my library for di. Generating metadata for new decorators is very necessary.
I am also seeing this issue. Here is the playground link.
I have set the emitDecoratorMetadata
to true
, but the emitted code does not contain the desgin:type
metadata.
I think the title of issue needs to be changed to something like TC39 Decorators does not emit metadata to Symbol.Metadata
Also reviewing the code it looks like it is not implemented here https://github.com/microsoft/TypeScript/blob/v5.3.3/src/compiler/transformers/ts.ts#L1064
I also thing that emitting type metadata is very necessary, but now that both Decorators and Decorator Metadata have achieved Stage 3 within TC39 and have been implemented in TS >=5.2, the API proposed in the reflect-metadata
library is no longer being considered for standardization.
This is why I think that is better to expose design-time type information in the new TC39 decorator metadata when emitDecoratorMetadata: true
.
I also thing that emitting type metadata is very necessary, but now that both Decorators and Decorator Metadata have achieved Stage 3 within TC39 and have been implemented in TS >=5.2, the API proposed in the
reflect-metadata
library is no longer being considered for standardization.This is why I think that is better to expose design-time type information in the new TC39 decorator metadata when
emitDecoratorMetadata: true
.
Inclined to agree @artberri. I've raised a PR to serve as a PoC / proposal for how this could be implemented. A lot of the foundations were already set, so this barely required any changes.
π Search Terms
decorator, experimentalDecorators, emitDecoratorMetadata, TC39, reflect-metadata, Reflect.metadata(k, v)
π Version & Regression Information
This breaks when setting disabling experimental decorators
β― Playground Link
https://github.com/paulsmithkc/typescript-decorators
π» Code
tsconfig.json
src/index.ts
run with:
π Actual behavior
Reflect.getMetadata('design:type', target, property)
returns undefined.π Expected behavior
Reflect.getMetadata('design:type', target, property)
returns the type of the class field, when using Standard TC39 decorators.Additional information about the issue
When transpiling with:
The decorator
Reflect.metadata("design:type", type)
is automatically applied to each class field.When transpiling with:
The decorator
Reflect.metadata("design:type", type)
is not applied.When transpiling with:
Typescript produces the following error