Skip to content

Regression: decorator must be on first of the defined property methods #12554

Closed

Description

@wardbell

TypeScript Version: 2.1.1

In 2.0.10, a decorator such as the Angular @Input decorator could appear on the second of the two methods implementing a defined property. As of 2.1.1, you get an error unless it appears on the first.

Expected behavior:
The code should work as it does when transpiled with 2.0.10

Actual behavior:
The code fails with 2.1.1

Repro
Here is my plunker. Follow the README.

To see that changing the TypeScript version controls the outcome,
open config.js and toggle the TypeScript version to 2.0.10 to see that the code works fine when the decorator is on the second property method.

I compared the generated JS under TS 2.0.10 and 2.1.1.
The latter, failing version is missing the following important code:

  __decorate([
            core_1.Input(), 
            __metadata('design:type', Number)
        ], CustomComponent.prototype, "selectedSection", null);

This explains why the Angular app fails: Angular can't find that decorator and therefore proclaims that the CustomComponent does not have a bindable selectedSection property.

View Angular issue "Setter @Input binding not working after upgrading to 2.2.3 from 2.1.2 " see how this issue arose, That issue is closed because we believe this is actually a TS issue.

Activity

  1. mhegazy commented on Dec 12, 2016

    @mhegazy
    Contributor

    Ron Buckton (@rbuckton) can you take a look.

  2. rbuckton commented on Apr 25, 2017

    @rbuckton
    Contributor

    This was fixed for 2.1.5 via #12740, and is still working as of 2.3.0.

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions