Skip to content

Breaking changes in 2.1.4 with NG2.1 #12727

Closed

Description

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.
Laurence Mercer (@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'.
Laurence Mercer (@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;
      }

Activity

  1. mhegazy commented on Dec 7, 2016

    @mhegazy
    Contributor

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

  2. rbuckton commented on Dec 7, 2016

    @rbuckton
    Contributor

    Mohamed Hegazy (@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.

  3. mhegazy commented on Dec 8, 2016

    @mhegazy
    Contributor

    Brachi Packter (@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.

  4. brachi-wernick commented on Dec 8, 2016

    @brachi-wernick
    Author

    Mohamed Hegazy (@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) { }
    }
    
  5. aluanhaddad commented on Dec 8, 2016

    @aluanhaddad
    Contributor

    the fix should be in typescript@next later tonight.

    Mohamed Hegazy (@mhegazy) It is working for me with typescript@2.2.0-dev.20161208

    Brachi Packter (@brachi-wernick) @latest is the latest release.

  6. aluanhaddad commented on Dec 8, 2016

    @aluanhaddad
    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.

  7. rbuckton commented on Dec 9, 2016

    @rbuckton
    Contributor

    Aluan Haddad (@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.

  8. 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 TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions