Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27225,7 +27225,7 @@ namespace ts {
reference.expression.parent = reference;
reference.parent = constructor;
reference.flowNode = constructor.returnFlowNode;
const flowType = getFlowTypeOfReference(reference, getOptionalType(propType));
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitial
let y = this.c;
}
}

// Property is considered initialized by type any even though value could be undefined

declare function someValue(): any;

class C11 {
a: number;
constructor() {
this.a = someValue();
}
}

22 changes: 22 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ class C10 {
let y = this.c;
}
}

// Property is considered initialized by type any even though value could be undefined

declare function someValue(): any;

class C11 {
a: number;
constructor() {
this.a = someValue();
}
}


//// [strictPropertyInitialization.js]
Expand Down Expand Up @@ -172,6 +183,12 @@ var C10 = /** @class */ (function () {
}
return C10;
}());
var C11 = /** @class */ (function () {
function C11() {
this.a = someValue();
}
return C11;
}());


//// [strictPropertyInitialization.d.ts]
Expand Down Expand Up @@ -227,3 +244,8 @@ declare class C10 {
c?: number;
constructor();
}
declare function someValue(): any;
declare class C11 {
a: number;
constructor();
}
20 changes: 20 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,23 @@ class C10 {
}
}

// Property is considered initialized by type any even though value could be undefined

declare function someValue(): any;
>someValue : Symbol(someValue, Decl(strictPropertyInitialization.ts, 97, 1))

class C11 {
>C11 : Symbol(C11, Decl(strictPropertyInitialization.ts, 101, 34))

a: number;
>a : Symbol(C11.a, Decl(strictPropertyInitialization.ts, 103, 11))

constructor() {
this.a = someValue();
>this.a : Symbol(C11.a, Decl(strictPropertyInitialization.ts, 103, 11))
>this : Symbol(C11, Decl(strictPropertyInitialization.ts, 101, 34))
>a : Symbol(C11.a, Decl(strictPropertyInitialization.ts, 103, 11))
>someValue : Symbol(someValue, Decl(strictPropertyInitialization.ts, 97, 1))
}
}

22 changes: 22 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.types
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,25 @@ class C10 {
}
}

// Property is considered initialized by type any even though value could be undefined

declare function someValue(): any;
>someValue : () => any

class C11 {
>C11 : C11

a: number;
>a : number

constructor() {
this.a = someValue();
>this.a = someValue() : any
>this.a : number
>this : this
>a : number
>someValue() : any
>someValue : () => any
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ class C10 {
let y = this.c;
}
}

// Property is considered initialized by type any even though value could be undefined

declare function someValue(): any;

class C11 {
a: number;
constructor() {
this.a = someValue();
}
}