Skip to content

Commit e128b94

Browse files
authored
Merge pull request #13192 from slawomir/13063-strictNullChecks-breaks-typeof
#13063 Fix strictNullChecks breaking typeof
2 parents b82fe52 + 5317f13 commit e128b94

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10372,7 +10372,7 @@ namespace ts {
1037210372
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
1037310373
// declaration container are the same).
1037410374
const assumeInitialized = isParameter || isOuterVariable ||
10375-
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) ||
10375+
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isInTypeQuery(node)) ||
1037610376
isInAmbientContext(declaration);
1037710377
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
1037810378
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [typeofStrictNull.ts]
2+
3+
let a: number;
4+
let b: typeof a;
5+
6+
//// [typeofStrictNull.js]
7+
var a;
8+
var b;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/typeofStrictNull.ts ===
2+
3+
let a: number;
4+
>a : Symbol(a, Decl(typeofStrictNull.ts, 1, 3))
5+
6+
let b: typeof a;
7+
>b : Symbol(b, Decl(typeofStrictNull.ts, 2, 3))
8+
>a : Symbol(a, Decl(typeofStrictNull.ts, 1, 3))
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/typeofStrictNull.ts ===
2+
3+
let a: number;
4+
>a : number
5+
6+
let b: typeof a;
7+
>b : number
8+
>a : number
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @strictNullChecks: true
2+
3+
let a: number;
4+
let b: typeof a;

0 commit comments

Comments
 (0)