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

Defined "set" property (and lack of "get" property) does not result in type "undefined" when accessing said property #17793

Closed
begincalendar opened this issue Aug 15, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@begincalendar
Copy link
Contributor

TypeScript Version: 2.4.1

Code

class MyClass {                                                              

  private _myVar: string;                                                    

  public constructor() {                                                     
    this._myVar = 'Hello world!';                                            
  }                                                                          

  public set myVar(value: string) {                                          
    this._myVar = value;                                                     
  }                                                                          

}                                                                            

const myObj = new MyClass();                                                 

const otherVar: string = myObj.myVar;

Expected behavior:

example.ts(17,7): error TS2322: Type 'undefined' is not assignable to type 'string'.

Actual behavior:

No error.

@kitsonk
Copy link
Contributor

kitsonk commented Aug 15, 2017

Duplicate of #11596

Search is your friend.

@begincalendar
Copy link
Contributor Author

Thanks.
I had actually tried to find an existing issue, but evidently not hard enough.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 15, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants