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

Decorate all properties with type metadata in TypeScript #11861

Closed
heruan opened this issue Oct 26, 2016 · 1 comment
Closed

Decorate all properties with type metadata in TypeScript #11861

heruan opened this issue Oct 26, 2016 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@heruan
Copy link

heruan commented Oct 26, 2016

I'm working on a JSON Object-Mapper which would parse a JSON string and produce typed objects, i.e.

class Bar {}
class Foo {
    bar: Bar;
}
let json = '{"bar":{}}';
let foo = mapper.fromString(json, Foo);
expect(foo instanceof Foo).toBe(true);
expect(foo.bar instanceof Bar).toBe(true);

For this I need design:type metadata for all properties, but I see it's emitted only if a property is decorated (also a bogus decorator will do), e.g.

class Foo {                 var Foo = (function () {
    bar: Bar;                   function Foo() {
}                               }
                                return Foo;
                            }());

function bogus(t, k) {}

class Foo {                 var Foo = (function () {
    @bogus bar: Bar;            function Foo() {
}                               }
                                __decorate([
                                    bogus, 
                                    __metadata('design:type', Bar)
                                ], Foo.prototype, "bar", void 0);
                                return Foo;
                            }());

It would be very useful to have a compiler option to enable the implicit metadata decoration for all design:* metadata, without the need of an additional decorator.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 26, 2016

Metadata is just a decorator, just one that the compiler emits. decorating all propoerties/method/classes would explode the size of the output, will cause a decorator call for every declaration. it is not clear that there is much utility of this despite the cost. you can see more discussion about why this does not really work for the general case in #3628.

@mhegazy mhegazy added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Oct 26, 2016
@heruan heruan closed this as completed Dec 6, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants