Skip to content

[Bug] Non-public access modifier keywords break lexical scope for property access #226

@mike-north

Description

@mike-north

Steps to reproduce:

  1. Create a new ember app
  2. Install ember-cli-typescript
  3. ember g route home
  4. Replace your home route's code with something like this
import Route from "@ember/routing/route";

export default class Home extends Route {
  public tool = "ember-cli";
  public model(): any {
    return ["ember", "ember-data", this.get("tool")];
  }
  protected foo() {}
}

What I expected

The presence of a private or protected foo() {} method should not cause other methods in the class to break. I should be free to call foo() from other public, private or protected methods, and see behavior in alignment with the way things work in vanilla TypeScript classes.

What I saw instead

Compilation error on the this.get("tool"):

[ts]
The 'this' context of type 'this' is not assignable to method's 'this' of type 'ComputedPropertyGetters<{ tool: string; model: () => any; foo: () => void; afterModel: (resolvedM...'.
  Type 'Home' is not assignable to type 'ComputedPropertyGetters<{ tool: string; model: () => any; foo: () => void; afterModel: (resolvedM...'.
    Property 'foo' is protected in type 'Home' but public in type 'ComputedPropertyGetters<{ tool: string; model: () => any; foo: () => void; afterModel: (resolvedM...'.

Related: #212 #176

Even if this is a "known limitation", we should track these kinds of things as bugs so they can be triaged and focused on appropriately. Two teams currently trying to adopt Ember+TS were questioning their own sanity for a few days last week, because they found no info (issues/PRs/documentation) that shed light on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtypes:coreSomething is wrong with the Ember type definitions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions