ember-cli-typescript icon indicating copy to clipboard operation
ember-cli-typescript copied to clipboard

Different behavior when using a private vs a public property

Open boris-petrov opened this issue 7 years ago • 2 comments

Which package(s) does this problem pertain to?

  • [x] @types/ember
  • [x] @types/ember__object

Having a:

class extends Controller {
  private foo?: string;
  public bar?: string;

  public clear() {
    this.set('foo', undefined);
    this.set('bar', undefined);
  }
}

Leads to a single warning error TS2345: Argument of type '"foo"' is not assignable to parameter of type 'keyof this'.. I can't begin to imagine why is the warning there for private fields but not for public ones? Is this a bug in Ember's type definitions or in TypeScript? Or is this by design?

boris-petrov avatar Oct 19 '18 11:10 boris-petrov

This used to be a limitation of our type definitions, but it should have been fixed when we resolved #226 via definitelytyped/definitelytyped#28282.

@mike-north or @dwickern do you have any idea what the state is on this?

chriskrycho avatar Oct 21 '18 03:10 chriskrycho

This is by design according to https://github.com/Microsoft/TypeScript/issues/13543

dwickern avatar Oct 22 '18 19:10 dwickern