Merge pull request #33199 from jack-williams/fix-32809

Fix #32809
This commit is contained in:
Orta
2019-09-11 21:07:00 +02:00
committed by GitHub
6 changed files with 89 additions and 2 deletions
+1 -1
View File
@@ -18059,7 +18059,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 || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isBindingElement(declaration) ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.AnyOrUnknown) !== 0 ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
isInTypeQuery(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
node.parent.kind === SyntaxKind.NonNullExpression ||
declaration.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>declaration).exclamationToken ||
@@ -256,7 +256,7 @@ const v5 = v && v;
>v5 : void
>v && v : void
>v : void
>v : never
>v : void
const v6 = v && u;
>v6 : void
@@ -0,0 +1,23 @@
//// [voidIsInitialized.ts]
const x: void = undefined;
const y: void = undefined;
if(typeof x === "undefined") {
x // no error: assume x2 is initialised
}
if(typeof y !== "undefined") {
y // no error: do not narrow void
}
//// [voidIsInitialized.js]
"use strict";
var x = undefined;
var y = undefined;
if (typeof x === "undefined") {
x; // no error: assume x2 is initialised
}
if (typeof y !== "undefined") {
y; // no error: do not narrow void
}
@@ -0,0 +1,23 @@
=== tests/cases/compiler/voidIsInitialized.ts ===
const x: void = undefined;
>x : Symbol(x, Decl(voidIsInitialized.ts, 0, 5))
>undefined : Symbol(undefined)
const y: void = undefined;
>y : Symbol(y, Decl(voidIsInitialized.ts, 1, 5))
>undefined : Symbol(undefined)
if(typeof x === "undefined") {
>x : Symbol(x, Decl(voidIsInitialized.ts, 0, 5))
x // no error: assume x2 is initialised
>x : Symbol(x, Decl(voidIsInitialized.ts, 0, 5))
}
if(typeof y !== "undefined") {
>y : Symbol(y, Decl(voidIsInitialized.ts, 1, 5))
y // no error: do not narrow void
>y : Symbol(y, Decl(voidIsInitialized.ts, 1, 5))
}
@@ -0,0 +1,29 @@
=== tests/cases/compiler/voidIsInitialized.ts ===
const x: void = undefined;
>x : void
>undefined : undefined
const y: void = undefined;
>y : void
>undefined : undefined
if(typeof x === "undefined") {
>typeof x === "undefined" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : void
>"undefined" : "undefined"
x // no error: assume x2 is initialised
>x : void
}
if(typeof y !== "undefined") {
>typeof y !== "undefined" : boolean
>typeof y : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>y : void
>"undefined" : "undefined"
y // no error: do not narrow void
>y : void
}
+12
View File
@@ -0,0 +1,12 @@
// @strict: true
const x: void = undefined;
const y: void = undefined;
if(typeof x === "undefined") {
x // no error: assume x2 is initialised
}
if(typeof y !== "undefined") {
y // no error: do not narrow void
}