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

Breaking changes in 2.1.4 with NG2.1 #12727

Closed
brachi-wernick opened this issue Dec 7, 2016 · 7 comments · Fixed by #12740
Closed

Breaking changes in 2.1.4 with NG2.1 #12727

brachi-wernick opened this issue Dec 7, 2016 · 7 comments · Fixed by #12740
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@brachi-wernick
Copy link

TypeScript Version: 2.1.4 with ng 2.1.x

Code1 failed:

    private _value:string;
  
  set value(value: string) {
            this._value = value;
      }

@Input()
   get value() {
        return this._value;
    }

Code2 failed:

    private _value:string;

  get value() {
        return this._value;
    }

  @Input()
    set value(value: string) {
            this._value = value;
      }

Expected behavior:
should work as before upgrade, I can use the value as input in html.
@input can be above a get method or above a set method. and get/set method can appear in the class in each place.

Actual behavior:
get an error: Can't bind to 'value' since it isn't a known property of 'some-componnet'.
@input must be in the get method, but get method must appears before the set method.

this code works: but for me it is workaround:

Code1 failed:

    private _value:string;
//I change order of the get to be before the set
@Input()
   get value() {
        return this._value;
    }

    set value(value: string) {
            this._value = value;
      }

Code2 failed:

    private _value:string;
//I remove annotation from the set method and put above the get
@Input()
   get value() {
        return this._value;
    }

  
    set value(value: string) {
            this._value = value;
      }
@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

@brachi-wernick can you share more context? i can not piece together a self-contained repro using your snippets.

@rbuckton
Copy link
Member

rbuckton commented Dec 7, 2016

@mhegazy Here's a simple repro:

declare var Input: any;

class A {
    @Input() set value(value: string) { } // works
    get value() { return ""; }
}

class B {
    set value(value: string) { }
    @Input() get value() { return ""; } // does not work
}

It looks like decorators on the second declaration are not emitted.

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 7, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 8, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Dec 8, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2016

@brachi-wernick the fix should be in typescript@next later tonight. please give it a try and let us know if you are still running into issues.

@brachi-wernick
Copy link
Author

brachi-wernick commented Dec 8, 2016

@mhegazy I checked the @latest in that is what I found:

declare var Input: any;

class A {
    set value(value: string) { }
    @Input() get value() { return ""; } // fixed, works now
}

class B { 
   get value() { return ""; } // still doesn't work
   @Input() set value(value: string) { }
}

@mhegazy mhegazy reopened this Dec 8, 2016
@mhegazy mhegazy removed the Fixed A PR has been merged for this issue label Dec 8, 2016
@aluanhaddad
Copy link
Contributor

the fix should be in typescript@next later tonight.

@mhegazy It is working for me with [email protected]

@brachi-wernick @latest is the latest release.

@aluanhaddad
Copy link
Contributor

Something interesting is that I get an empty array for the design:paramtypes key when the getter is decorated, but a singleton array if the setter is. In 2.0.8, there is no emit for that key. Is this a new feature? Just curious.

@rbuckton
Copy link
Member

rbuckton commented Dec 9, 2016

@aluanhaddad As getters cannot have parameters, the design:paramtypes metadata should always be for the setter, if it has one. It looks like this is a bug in 2.0.8 and in 2.1.

@mhegazy mhegazy closed this as completed Dec 13, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 13, 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
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants