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

[feature request] consistent index access type for this type #12349

Closed
HerringtonDarkholme opened this issue Nov 18, 2016 · 3 comments
Closed

Comments

@HerringtonDarkholme
Copy link
Contributor

Sorry it's me again....
it seems this type is resolved too eagerly in parent class.

TypeScript Version: nightly

Code

class A {
  prop: {}
  propCopy: this['prop']
}

class B extends A {
  prop: {field: number}
  propCopy2: this['prop']
}

var b = new B
b.propCopy.field // error here
b.propCopy2.field

Expected behavior:

Code should compile. both propCopy and propCopy2 have the same type.

Actual behavior:

Error on b.propCopy.field, b.propCopy is typed as {}

@aluanhaddad
Copy link
Contributor

This behavior seems to make sense. prop doesn't have a field property in the base class where propCopy is defined. If you redefine the field on the subclass the error goes away.

@HerringtonDarkholme
Copy link
Contributor Author

I believe this is the same issue with #11929 (comment)

It is not a bug report but a feature request.

@aluanhaddad
Copy link
Contributor

@HerringtonDarkholme I see. I was thinking about it as a bug report, sorry.

@HerringtonDarkholme HerringtonDarkholme changed the title Inconsistent index access type for this type [feature request] consistent index access type for this type Nov 21, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants