Merge pull request #13192 from slawomir/13063-strictNullChecks-breaks-typeof

#13063 Fix strictNullChecks breaking typeof
This commit is contained in:
Mohamed Hegazy 2016-12-28 12:52:21 -08:00 committed by GitHub
commit e128b94dc2
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 || (type.flags & TypeFlags.Any) !== 0 || isInTypeQuery(node)) ||
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;