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

Return type not inferred correctly in static method #7497

Closed
SylvainEstevez opened this issue Mar 13, 2016 · 1 comment
Closed

Return type not inferred correctly in static method #7497

SylvainEstevez opened this issue Mar 13, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@SylvainEstevez
Copy link

TypeScript Version:
1.8.7

Code

'use strict';

class User {
  firstName: string;
  lastName: string;  

  static getInstance() {
    return new this();
  }
}

class StaffUser extends User {  
  position: string;
}

let staffUser = StaffUser.getInstance();

console.log(staffUser.position); // error TS2339: Property 'position' does not exist on type 'User'

Expected behavior:

staffUser should be of type StaffUser, not simply User.

Actual behavior:
The compiler doesn't guess that getInstance in StaffUser returns instances of StaffUser.

@vladima vladima added the Duplicate An existing issue was already created label Mar 13, 2016
@vladima
Copy link
Contributor

vladima commented Mar 13, 2016

duplicate of #5863

@vladima vladima closed this as completed Mar 13, 2016
@vladima vladima reopened this Mar 14, 2016
@vladima vladima closed this as completed Mar 14, 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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants