mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #13192 from slawomir/13063-strictNullChecks-breaks-typeof
#13063 Fix strictNullChecks breaking typeof
This commit is contained in:
commit
e128b94dc2
@ -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
|
||||
|
||||
8
tests/baselines/reference/typeofStrictNull.js
Normal file
8
tests/baselines/reference/typeofStrictNull.js
Normal file
@ -0,0 +1,8 @@
|
||||
//// [typeofStrictNull.ts]
|
||||
|
||||
let a: number;
|
||||
let b: typeof a;
|
||||
|
||||
//// [typeofStrictNull.js]
|
||||
var a;
|
||||
var b;
|
||||
9
tests/baselines/reference/typeofStrictNull.symbols
Normal file
9
tests/baselines/reference/typeofStrictNull.symbols
Normal 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))
|
||||
|
||||
9
tests/baselines/reference/typeofStrictNull.types
Normal file
9
tests/baselines/reference/typeofStrictNull.types
Normal file
@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/typeofStrictNull.ts ===
|
||||
|
||||
let a: number;
|
||||
>a : number
|
||||
|
||||
let b: typeof a;
|
||||
>b : number
|
||||
>a : number
|
||||
|
||||
4
tests/cases/compiler/typeofStrictNull.ts
Normal file
4
tests/cases/compiler/typeofStrictNull.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
let a: number;
|
||||
let b: typeof a;
|
||||
Loading…
x
Reference in New Issue
Block a user