mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-02 14:48:32 -05:00
Add new tests
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
//// [constLocalsInFunctionExpressions.ts]
|
||||
declare function getStringOrNumber(): string | number;
|
||||
|
||||
function f1() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = () => x.length;
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
const f = () => x.length;
|
||||
}
|
||||
|
||||
function f3() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = function() { return x.length; };
|
||||
}
|
||||
}
|
||||
|
||||
function f4() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
const f = function() { return x.length; };
|
||||
}
|
||||
|
||||
function f5() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = () => () => x.length;
|
||||
}
|
||||
}
|
||||
|
||||
//// [constLocalsInFunctionExpressions.js]
|
||||
function f1() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
var f = function () { return x.length; };
|
||||
}
|
||||
}
|
||||
function f2() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
var f = function () { return x.length; };
|
||||
}
|
||||
function f3() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
var f = function () { return x.length; };
|
||||
}
|
||||
}
|
||||
function f4() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
var f = function () { return x.length; };
|
||||
}
|
||||
function f5() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
var f = function () { return function () { return x.length; }; };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
=== tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts ===
|
||||
declare function getStringOrNumber(): string | number;
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
function f1() {
|
||||
>f1 : Symbol(f1, Decl(constLocalsInFunctionExpressions.ts, 0, 54))
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9))
|
||||
|
||||
const f = () => x.length;
|
||||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 5, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : Symbol(f2, Decl(constLocalsInFunctionExpressions.ts, 7, 1))
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
if (typeof x !== "string") {
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9))
|
||||
|
||||
return;
|
||||
}
|
||||
const f = () => x.length;
|
||||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 14, 9))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
||||
function f3() {
|
||||
>f3 : Symbol(f3, Decl(constLocalsInFunctionExpressions.ts, 15, 1))
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9))
|
||||
|
||||
const f = function() { return x.length; };
|
||||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 20, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
}
|
||||
|
||||
function f4() {
|
||||
>f4 : Symbol(f4, Decl(constLocalsInFunctionExpressions.ts, 22, 1))
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
if (typeof x !== "string") {
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9))
|
||||
|
||||
return;
|
||||
}
|
||||
const f = function() { return x.length; };
|
||||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 29, 9))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
||||
function f5() {
|
||||
>f5 : Symbol(f5, Decl(constLocalsInFunctionExpressions.ts, 30, 1))
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9))
|
||||
|
||||
const f = () => () => x.length;
|
||||
>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 35, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
}
|
||||
121
tests/baselines/reference/constLocalsInFunctionExpressions.types
Normal file
121
tests/baselines/reference/constLocalsInFunctionExpressions.types
Normal file
@@ -0,0 +1,121 @@
|
||||
=== tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts ===
|
||||
declare function getStringOrNumber(): string | number;
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
function f1() {
|
||||
>f1 : () => void
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
const f = () => x.length;
|
||||
>f : () => number
|
||||
>() => x.length : () => number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : () => void
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x !== "string") {
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
return;
|
||||
}
|
||||
const f = () => x.length;
|
||||
>f : () => number
|
||||
>() => x.length : () => number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
|
||||
function f3() {
|
||||
>f3 : () => void
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
const f = function() { return x.length; };
|
||||
>f : () => number
|
||||
>function() { return x.length; } : () => number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
}
|
||||
|
||||
function f4() {
|
||||
>f4 : () => void
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x !== "string") {
|
||||
>typeof x !== "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
return;
|
||||
}
|
||||
const f = function() { return x.length; };
|
||||
>f : () => number
|
||||
>function() { return x.length; } : () => number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
|
||||
function f5() {
|
||||
>f5 : () => void
|
||||
|
||||
const x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
const f = () => () => x.length;
|
||||
>f : () => () => number
|
||||
>() => () => x.length : () => () => number
|
||||
>() => x.length : () => number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
}
|
||||
}
|
||||
87
tests/baselines/reference/controlFlowIIFE.js
Normal file
87
tests/baselines/reference/controlFlowIIFE.js
Normal file
@@ -0,0 +1,87 @@
|
||||
//// [controlFlowIIFE.ts]
|
||||
|
||||
declare function getStringOrNumber(): string | number;
|
||||
|
||||
function f1() {
|
||||
let x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
let n = function() {
|
||||
return x.length;
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
let n = (function() {
|
||||
return x.length;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function f3() {
|
||||
let x = getStringOrNumber();
|
||||
let y: number;
|
||||
if (typeof x === "string") {
|
||||
let n = (z => x.length + y + z)(y = 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Repros from #8381
|
||||
|
||||
let maybeNumber: number | undefined;
|
||||
(function () {
|
||||
maybeNumber = 1;
|
||||
})();
|
||||
if (maybeNumber !== undefined) {
|
||||
maybeNumber++;
|
||||
}
|
||||
|
||||
let test: string | undefined;
|
||||
if (!test) {
|
||||
throw new Error('Test is not defined');
|
||||
}
|
||||
(() => {
|
||||
test.slice(1); // No error
|
||||
})();
|
||||
|
||||
//// [controlFlowIIFE.js]
|
||||
function f1() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
var n = function () {
|
||||
return x.length;
|
||||
}();
|
||||
}
|
||||
}
|
||||
function f2() {
|
||||
var x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
var n = (function () {
|
||||
return x.length;
|
||||
})();
|
||||
}
|
||||
}
|
||||
function f3() {
|
||||
var x = getStringOrNumber();
|
||||
var y;
|
||||
if (typeof x === "string") {
|
||||
var n = (function (z) { return x.length + y + z; })(y = 1);
|
||||
}
|
||||
}
|
||||
// Repros from #8381
|
||||
var maybeNumber;
|
||||
(function () {
|
||||
maybeNumber = 1;
|
||||
})();
|
||||
if (maybeNumber !== undefined) {
|
||||
maybeNumber++;
|
||||
}
|
||||
var test;
|
||||
if (!test) {
|
||||
throw new Error('Test is not defined');
|
||||
}
|
||||
(function () {
|
||||
test.slice(1); // No error
|
||||
})();
|
||||
108
tests/baselines/reference/controlFlowIIFE.symbols
Normal file
108
tests/baselines/reference/controlFlowIIFE.symbols
Normal file
@@ -0,0 +1,108 @@
|
||||
=== tests/cases/conformance/controlFlow/controlFlowIIFE.ts ===
|
||||
|
||||
declare function getStringOrNumber(): string | number;
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0))
|
||||
|
||||
function f1() {
|
||||
>f1 : Symbol(f1, Decl(controlFlowIIFE.ts, 1, 54))
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7))
|
||||
|
||||
let n = function() {
|
||||
>n : Symbol(n, Decl(controlFlowIIFE.ts, 6, 11))
|
||||
|
||||
return x.length;
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : Symbol(f2, Decl(controlFlowIIFE.ts, 10, 1))
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7))
|
||||
|
||||
let n = (function() {
|
||||
>n : Symbol(n, Decl(controlFlowIIFE.ts, 15, 11))
|
||||
|
||||
return x.length;
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function f3() {
|
||||
>f3 : Symbol(f3, Decl(controlFlowIIFE.ts, 19, 1))
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7))
|
||||
>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0))
|
||||
|
||||
let y: number;
|
||||
>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7))
|
||||
|
||||
if (typeof x === "string") {
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7))
|
||||
|
||||
let n = (z => x.length + y + z)(y = 1);
|
||||
>n : Symbol(n, Decl(controlFlowIIFE.ts, 25, 11))
|
||||
>z : Symbol(z, Decl(controlFlowIIFE.ts, 25, 17))
|
||||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7))
|
||||
>z : Symbol(z, Decl(controlFlowIIFE.ts, 25, 17))
|
||||
>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7))
|
||||
}
|
||||
}
|
||||
|
||||
// Repros from #8381
|
||||
|
||||
let maybeNumber: number | undefined;
|
||||
>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3))
|
||||
|
||||
(function () {
|
||||
maybeNumber = 1;
|
||||
>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3))
|
||||
|
||||
})();
|
||||
if (maybeNumber !== undefined) {
|
||||
>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
maybeNumber++;
|
||||
>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3))
|
||||
}
|
||||
|
||||
let test: string | undefined;
|
||||
>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3))
|
||||
|
||||
if (!test) {
|
||||
>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3))
|
||||
|
||||
throw new Error('Test is not defined');
|
||||
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
}
|
||||
(() => {
|
||||
test.slice(1); // No error
|
||||
>test.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
|
||||
>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3))
|
||||
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
|
||||
|
||||
})();
|
||||
149
tests/baselines/reference/controlFlowIIFE.types
Normal file
149
tests/baselines/reference/controlFlowIIFE.types
Normal file
@@ -0,0 +1,149 @@
|
||||
=== tests/cases/conformance/controlFlow/controlFlowIIFE.ts ===
|
||||
|
||||
declare function getStringOrNumber(): string | number;
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
function f1() {
|
||||
>f1 : () => void
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
let n = function() {
|
||||
>n : number
|
||||
>function() { return x.length; }() : number
|
||||
>function() { return x.length; } : () => number
|
||||
|
||||
return x.length;
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : () => void
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
let n = (function() {
|
||||
>n : number
|
||||
>(function() { return x.length; })() : number
|
||||
>(function() { return x.length; }) : () => number
|
||||
>function() { return x.length; } : () => number
|
||||
|
||||
return x.length;
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function f3() {
|
||||
>f3 : () => void
|
||||
|
||||
let x = getStringOrNumber();
|
||||
>x : string | number
|
||||
>getStringOrNumber() : string | number
|
||||
>getStringOrNumber : () => string | number
|
||||
|
||||
let y: number;
|
||||
>y : number
|
||||
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | number
|
||||
>"string" : string
|
||||
|
||||
let n = (z => x.length + y + z)(y = 1);
|
||||
>n : number
|
||||
>(z => x.length + y + z)(y = 1) : number
|
||||
>(z => x.length + y + z) : (z: number) => number
|
||||
>z => x.length + y + z : (z: number) => number
|
||||
>z : number
|
||||
>x.length + y + z : number
|
||||
>x.length + y : number
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
>y : number
|
||||
>z : number
|
||||
>y = 1 : number
|
||||
>y : number
|
||||
>1 : number
|
||||
}
|
||||
}
|
||||
|
||||
// Repros from #8381
|
||||
|
||||
let maybeNumber: number | undefined;
|
||||
>maybeNumber : number | undefined
|
||||
|
||||
(function () {
|
||||
>(function () { maybeNumber = 1;})() : void
|
||||
>(function () { maybeNumber = 1;}) : () => void
|
||||
>function () { maybeNumber = 1;} : () => void
|
||||
|
||||
maybeNumber = 1;
|
||||
>maybeNumber = 1 : number
|
||||
>maybeNumber : number | undefined
|
||||
>1 : number
|
||||
|
||||
})();
|
||||
if (maybeNumber !== undefined) {
|
||||
>maybeNumber !== undefined : boolean
|
||||
>maybeNumber : number | undefined
|
||||
>undefined : undefined
|
||||
|
||||
maybeNumber++;
|
||||
>maybeNumber++ : number
|
||||
>maybeNumber : number
|
||||
}
|
||||
|
||||
let test: string | undefined;
|
||||
>test : string | undefined
|
||||
|
||||
if (!test) {
|
||||
>!test : boolean
|
||||
>test : string | undefined
|
||||
|
||||
throw new Error('Test is not defined');
|
||||
>new Error('Test is not defined') : Error
|
||||
>Error : ErrorConstructor
|
||||
>'Test is not defined' : string
|
||||
}
|
||||
(() => {
|
||||
>(() => { test.slice(1); // No error})() : void
|
||||
>(() => { test.slice(1); // No error}) : () => void
|
||||
>() => { test.slice(1); // No error} : () => void
|
||||
|
||||
test.slice(1); // No error
|
||||
>test.slice(1) : string
|
||||
>test.slice : (start?: number | undefined, end?: number | undefined) => string
|
||||
>test : string
|
||||
>slice : (start?: number | undefined, end?: number | undefined) => string
|
||||
>1 : number
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,38 @@
|
||||
declare function getStringOrNumber(): string | number;
|
||||
|
||||
function f1() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = () => x.length;
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
const f = () => x.length;
|
||||
}
|
||||
|
||||
function f3() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = function() { return x.length; };
|
||||
}
|
||||
}
|
||||
|
||||
function f4() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x !== "string") {
|
||||
return;
|
||||
}
|
||||
const f = function() { return x.length; };
|
||||
}
|
||||
|
||||
function f5() {
|
||||
const x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
const f = () => () => x.length;
|
||||
}
|
||||
}
|
||||
47
tests/cases/conformance/controlFlow/controlFlowIIFE.ts
Normal file
47
tests/cases/conformance/controlFlow/controlFlowIIFE.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
declare function getStringOrNumber(): string | number;
|
||||
|
||||
function f1() {
|
||||
let x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
let n = function() {
|
||||
return x.length;
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x = getStringOrNumber();
|
||||
if (typeof x === "string") {
|
||||
let n = (function() {
|
||||
return x.length;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
function f3() {
|
||||
let x = getStringOrNumber();
|
||||
let y: number;
|
||||
if (typeof x === "string") {
|
||||
let n = (z => x.length + y + z)(y = 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Repros from #8381
|
||||
|
||||
let maybeNumber: number | undefined;
|
||||
(function () {
|
||||
maybeNumber = 1;
|
||||
})();
|
||||
if (maybeNumber !== undefined) {
|
||||
maybeNumber++;
|
||||
}
|
||||
|
||||
let test: string | undefined;
|
||||
if (!test) {
|
||||
throw new Error('Test is not defined');
|
||||
}
|
||||
(() => {
|
||||
test.slice(1); // No error
|
||||
})();
|
||||
Reference in New Issue
Block a user