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

Abstract property access error occurs in non-abstract class constructors #19197

Closed
sirtrollraptor opened this issue Oct 15, 2017 · 3 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@sirtrollraptor
Copy link

TypeScript Version: starting from 2.6.0-dev.20171010, 2.6.0-dev.20171015

Code

abstract class Animal {
  public abstract name: string;
}

class Cat extends Animal {
  public name = "Cat";
}

class Foo {
  constructor(animal: Animal) {
    animal.name;
  }
}

new Foo(new Cat());

Expected behavior:
No compilation error should occur.

Actual behavior:
index.ts(11,12): error TS2715: Abstract property 'name' in class 'Animal' cannot be accessed in the constructor.
This regression was introduced in #19005, as accessing an abstract property in any constructor causes this error, rather than the indented goal of disallowing abstract property accesses only in the constructors of abstract classes that are/extend the abstract class that the abstract property belongs to.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 16, 2017
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.6.1 milestone Oct 16, 2017
@RyanCavanaugh
Copy link
Member

@sandersn can you take a look ASAP? Thanks!

@sandersn
Copy link
Member

The error is just missing a check that the usage is inside the constructor of the declaring class, not just any constructor. I'll add the check.

@sandersn sandersn added the Fixed A PR has been merged for this issue label Oct 16, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 16, 2017

The original change is 2.7 bound, so this fix needs to go into master.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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
Projects
None yet
Development

No branches or pull requests

4 participants