mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
83 lines
1.9 KiB
Plaintext
83 lines
1.9 KiB
Plaintext
controlFlowDoWhileStatement.ts(23,9): error TS2322: Type 'undefined' is not assignable to type 'string | number'.
|
|
|
|
|
|
==== controlFlowDoWhileStatement.ts (1 errors) ====
|
|
let cond: boolean;
|
|
function a() {
|
|
let x: string | number;
|
|
x = "";
|
|
do {
|
|
x; // string
|
|
} while (cond)
|
|
}
|
|
function b() {
|
|
let x: string | number;
|
|
x = "";
|
|
do {
|
|
x; // string
|
|
x = 42;
|
|
break;
|
|
} while (cond)
|
|
}
|
|
function c() {
|
|
let x: string | number;
|
|
x = "";
|
|
do {
|
|
x; // string
|
|
x = undefined;
|
|
~
|
|
!!! error TS2322: Type 'undefined' is not assignable to type 'string | number'.
|
|
if (typeof x === "string") continue;
|
|
break;
|
|
} while (cond)
|
|
}
|
|
function d() {
|
|
let x: string | number;
|
|
x = 1000;
|
|
do {
|
|
x; // number
|
|
x = "";
|
|
} while (x = x.length)
|
|
x; // number
|
|
}
|
|
function e() {
|
|
let x: string | number;
|
|
x = "";
|
|
do {
|
|
x = 42;
|
|
} while (cond)
|
|
x; // number
|
|
}
|
|
function f() {
|
|
let x: string | number | boolean | RegExp | Function;
|
|
x = "";
|
|
do {
|
|
if (cond) {
|
|
x = 42;
|
|
break;
|
|
}
|
|
if (cond) {
|
|
x = true;
|
|
continue;
|
|
}
|
|
x = /a/;
|
|
} while (cond)
|
|
x; // number | boolean | RegExp
|
|
}
|
|
function g() {
|
|
let x: string | number | boolean | RegExp | Function;
|
|
x = "";
|
|
do {
|
|
if (cond) {
|
|
x = 42;
|
|
break;
|
|
}
|
|
if (cond) {
|
|
x = true;
|
|
continue;
|
|
}
|
|
x = /a/;
|
|
} while (true)
|
|
x; // number
|
|
}
|
|
|