Skip to content

Cannot use this to index private or protected properties #17362

Closed
@Pauan

Description

@Pauan

TypeScript Version: 2.4.1

Code

This works fine:

class Foo {
  _foo: number;

  foo(): this["_foo"] {
    return this._foo;
  }
}

This works fine:

class Foo {
  protected _foo: number;

  foo(): Foo["_foo"] {
    return this._foo;
  }
}

I expect this to work, but it does not work:

class Foo {
  protected _foo: number;

  foo(): this["_foo"] {
    return this._foo;
  }
}

It fails with this error:

(4,10): error TS2536: Type '"_foo"' cannot be used to index type 'this'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions