Skip to content

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

@begincalendar

Description

@begincalendar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions