mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
116 lines
2.9 KiB
Plaintext
116 lines
2.9 KiB
Plaintext
controlFlowWhileStatement.ts(23,9): error TS2322: Type 'undefined' is not assignable to type 'string | number'.
|
|
controlFlowWhileStatement.ts(81,12): error TS2365: Operator '>' cannot be applied to types 'string | number' and 'number'.
|
|
|
|
|
|
==== controlFlowWhileStatement.ts (2 errors) ====
|
|
let cond: boolean;
|
|
function a() {
|
|
let x: string | number;
|
|
x = "";
|
|
while (cond) {
|
|
x; // string
|
|
}
|
|
}
|
|
function b() {
|
|
let x: string | number;
|
|
x = "";
|
|
while (cond) {
|
|
x; // string
|
|
x = 42;
|
|
break;
|
|
}
|
|
}
|
|
function c() {
|
|
let x: string | number;
|
|
x = "";
|
|
while (cond) {
|
|
x; // string
|
|
x = undefined;
|
|
~
|
|
!!! error TS2322: Type 'undefined' is not assignable to type 'string | number'.
|
|
if (typeof x === "string") continue;
|
|
break;
|
|
}
|
|
}
|
|
function d() {
|
|
let x: string | number;
|
|
x = "";
|
|
while (x = x.length) {
|
|
x; // number
|
|
x = "";
|
|
}
|
|
}
|
|
function e() {
|
|
let x: string | number;
|
|
x = "";
|
|
while (cond) {
|
|
x; // string | number
|
|
x = 42;
|
|
x; // number
|
|
}
|
|
x; // string | number
|
|
}
|
|
function f() {
|
|
let x: string | number | boolean | RegExp | Function;
|
|
x = "";
|
|
while (cond) {
|
|
if (cond) {
|
|
x = 42;
|
|
break;
|
|
}
|
|
if (cond) {
|
|
x = true;
|
|
continue;
|
|
}
|
|
x = /a/;
|
|
}
|
|
x; // string | number | boolean | RegExp
|
|
}
|
|
function g() {
|
|
let x: string | number | boolean | RegExp | Function;
|
|
x = "";
|
|
while (true) {
|
|
if (cond) {
|
|
x = 42;
|
|
break;
|
|
}
|
|
if (cond) {
|
|
x = true;
|
|
continue;
|
|
}
|
|
x = /a/;
|
|
}
|
|
x; // number
|
|
}
|
|
function h1() {
|
|
let x: string | number | boolean;
|
|
x = "";
|
|
while (x > 1) {
|
|
~~~~~
|
|
!!! error TS2365: Operator '>' cannot be applied to types 'string | number' and 'number'.
|
|
x; // string | number
|
|
x = 1;
|
|
x; // number
|
|
}
|
|
x; // string | number
|
|
}
|
|
declare function len(s: string | number): number;
|
|
function h2() {
|
|
let x: string | number | boolean;
|
|
x = "";
|
|
while (cond) {
|
|
x = len(x);
|
|
x; // number
|
|
}
|
|
x; // string | number
|
|
}
|
|
function h3() {
|
|
let x: string | number | boolean;
|
|
x = "";
|
|
while (cond) {
|
|
x; // string | number
|
|
x = len(x);
|
|
}
|
|
x; // string | number
|
|
}
|
|
|