Skip to content

some suggestions about emitDecoratorMetadata #34560

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

Closed
berbar opened this issue Oct 18, 2019 · 3 comments
Closed

some suggestions about emitDecoratorMetadata #34560

berbar opened this issue Oct 18, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@berbar
Copy link

berbar commented Oct 18, 2019

TypeScript Version: 3.7.0-dev.20191009

Search Terms:

It sets that 'emitDecoratorMetadata' is true in the 'tsconfig.json'.

If the classes depend on one another, It will occur exception.

Code

function TestReflect()
{
    return function( target: any, methodName?: string ): any
    {
    }
}

class Apple
{
    // Need Banana
    @TestReflect()
    public Some( banana: Banana )
    {
    }
}

@TestReflect()
class Banana
{
    // Need Apple
    public constructor( apple: Apple )
    {
    }
}

Expected behavior:

function TestReflect() {
    return function (target, methodName) {
    };
}
class Apple {
    Some(banana) {
    }
}
__decorate([
    TestReflect(),
    __metadata("design:type", Function),
    // __metadata("design:paramtypes", [Banana]),

    // i wish there is another new option to emit metadata like this
    // add a function '()=>Banana' into metadata
    __metadata("design:paramtypes:delay", [ ()=>Banana ] ),
    // or this
    // with more type informations
    __metadata("design:paramtypes:new", [ { GenericTypeDefinition: ()=>Banana, GenericArguments: [ () => Number ] }]),

    __metadata("design:returntype", void 0)
], Apple.prototype, "Some", null);
let Banana = class Banana {
    constructor(apple) {
    }
};
Banana = __decorate([
    TestReflect(),
    __metadata("design:paramtypes", [Apple])
], Banana);

Actual behavior:

function TestReflect() {
    return function (target, methodName) {
    };
}
class Apple {
    Some(banana) {
    }
}
__decorate([
    TestReflect(),
    __metadata("design:type", Function),
    // it will occur exception here.
    // Uncaught ReferenceError: Banana is not defined.
    __metadata("design:paramtypes", [Banana]),
    __metadata("design:returntype", void 0)
], Apple.prototype, "Some", null);
let Banana = class Banana {
    constructor(apple) {
    }
};
Banana = __decorate([
    TestReflect(),
    __metadata("design:paramtypes", [Apple])
], Banana);

Playground Link:

Related Issues:

@berbar
Copy link
Author

berbar commented Oct 18, 2019

    // option to emit the name of parameters
    __metadata("design:paramnames", [ "banana" ] ),

@MartinJohns
Copy link
Contributor

MartinJohns commented Oct 18, 2019

Looks like a duplicate of #27519.

And quoting @mhegazy:

The meta-data emit, continues to be an experimental feature tied to decorators, and has a very limited scope (i.e. classes and primitives). we have no plans to expand that scope either.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 30, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants