#13063 Fix strictNullChecks breaking typeof

* Allow typeof to use not-auto variable in strictNullChecks mode
This commit is contained in:
Slawomir Sadziak
2016-12-28 05:18:53 +01:00
parent 01a7ba8d47
commit 498568b16f
5 changed files with 31 additions and 1 deletions

View File

@@ -10372,7 +10372,7 @@ namespace ts {
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
// declaration container are the same).
const assumeInitialized = isParameter || isOuterVariable ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || isInTypeQuery(node) || (type.flags & TypeFlags.Any) !== 0) ||
isInAmbientContext(declaration);
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph

View File

@@ -0,0 +1,8 @@
//// [typeofStrictNull.ts]
let a: number;
let b: typeof a;
//// [typeofStrictNull.js]
var a;
var b;

View File

@@ -0,0 +1,9 @@
=== tests/cases/compiler/typeofStrictNull.ts ===
let a: number;
>a : Symbol(a, Decl(typeofStrictNull.ts, 1, 3))
let b: typeof a;
>b : Symbol(b, Decl(typeofStrictNull.ts, 2, 3))
>a : Symbol(a, Decl(typeofStrictNull.ts, 1, 3))

View File

@@ -0,0 +1,9 @@
=== tests/cases/compiler/typeofStrictNull.ts ===
let a: number;
>a : number
let b: typeof a;
>b : number
>a : number

View File

@@ -0,0 +1,4 @@
// @strictNullChecks: true
let a: number;
let b: typeof a;