mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #29756 from Microsoft/fixStrictPropertyInitialization
Revert change to strict property initialization checks
This commit is contained in:
commit
7c096576bc
@ -27249,7 +27249,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);
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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]
|
||||
@ -172,6 +183,12 @@ var C10 = /** @class */ (function () {
|
||||
}
|
||||
return C10;
|
||||
}());
|
||||
var C11 = /** @class */ (function () {
|
||||
function C11() {
|
||||
this.a = someValue();
|
||||
}
|
||||
return C11;
|
||||
}());
|
||||
|
||||
|
||||
//// [strictPropertyInitialization.d.ts]
|
||||
@ -227,3 +244,8 @@ declare class C10 {
|
||||
c?: number;
|
||||
constructor();
|
||||
}
|
||||
declare function someValue(): any;
|
||||
declare class C11 {
|
||||
a: number;
|
||||
constructor();
|
||||
}
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user