181 lines
4.9 KiB
Text
181 lines
4.9 KiB
Text
=== tests/cases/conformance/types/never/neverType.ts ===
|
|
|
|
|
|
function error(message: string): never {
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
>message : Symbol(message, Decl(neverType.ts, 2, 15))
|
|
|
|
throw new Error(message);
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
>message : Symbol(message, Decl(neverType.ts, 2, 15))
|
|
}
|
|
|
|
function errorVoid(message: string) {
|
|
>errorVoid : Symbol(errorVoid, Decl(neverType.ts, 4, 1))
|
|
>message : Symbol(message, Decl(neverType.ts, 6, 19))
|
|
|
|
throw new Error(message);
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
>message : Symbol(message, Decl(neverType.ts, 6, 19))
|
|
}
|
|
|
|
function fail() {
|
|
>fail : Symbol(fail, Decl(neverType.ts, 8, 1))
|
|
|
|
return error("Something failed");
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
}
|
|
|
|
function failOrThrow(shouldFail: boolean) {
|
|
>failOrThrow : Symbol(failOrThrow, Decl(neverType.ts, 12, 1))
|
|
>shouldFail : Symbol(shouldFail, Decl(neverType.ts, 14, 21))
|
|
|
|
if (shouldFail) {
|
|
>shouldFail : Symbol(shouldFail, Decl(neverType.ts, 14, 21))
|
|
|
|
return fail();
|
|
>fail : Symbol(fail, Decl(neverType.ts, 8, 1))
|
|
}
|
|
throw new Error();
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
}
|
|
|
|
function infiniteLoop1() {
|
|
>infiniteLoop1 : Symbol(infiniteLoop1, Decl(neverType.ts, 19, 1))
|
|
|
|
while (true) {
|
|
}
|
|
}
|
|
|
|
function infiniteLoop2(): never {
|
|
>infiniteLoop2 : Symbol(infiniteLoop2, Decl(neverType.ts, 24, 1))
|
|
|
|
while (true) {
|
|
}
|
|
}
|
|
|
|
function move1(direction: "up" | "down") {
|
|
>move1 : Symbol(move1, Decl(neverType.ts, 29, 1))
|
|
>direction : Symbol(direction, Decl(neverType.ts, 31, 15))
|
|
|
|
switch (direction) {
|
|
>direction : Symbol(direction, Decl(neverType.ts, 31, 15))
|
|
|
|
case "up":
|
|
return 1;
|
|
case "down":
|
|
return -1;
|
|
}
|
|
return error("Should never get here");
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
}
|
|
|
|
function move2(direction: "up" | "down") {
|
|
>move2 : Symbol(move2, Decl(neverType.ts, 39, 1))
|
|
>direction : Symbol(direction, Decl(neverType.ts, 41, 15))
|
|
|
|
return direction === "up" ? 1 :
|
|
>direction : Symbol(direction, Decl(neverType.ts, 41, 15))
|
|
|
|
direction === "down" ? -1 :
|
|
>direction : Symbol(direction, Decl(neverType.ts, 41, 15))
|
|
|
|
error("Should never get here");
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
}
|
|
|
|
function check<T>(x: T | undefined) {
|
|
>check : Symbol(check, Decl(neverType.ts, 45, 1))
|
|
>T : Symbol(T, Decl(neverType.ts, 47, 15))
|
|
>x : Symbol(x, Decl(neverType.ts, 47, 18))
|
|
>T : Symbol(T, Decl(neverType.ts, 47, 15))
|
|
|
|
return x || error("Undefined value");
|
|
>x : Symbol(x, Decl(neverType.ts, 47, 18))
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
}
|
|
|
|
class C {
|
|
>C : Symbol(C, Decl(neverType.ts, 49, 1))
|
|
|
|
void1() {
|
|
>void1 : Symbol(C.void1, Decl(neverType.ts, 51, 9))
|
|
|
|
throw new Error();
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
}
|
|
void2() {
|
|
>void2 : Symbol(C.void2, Decl(neverType.ts, 54, 5))
|
|
|
|
while (true) {}
|
|
}
|
|
never1(): never {
|
|
>never1 : Symbol(C.never1, Decl(neverType.ts, 57, 5))
|
|
|
|
throw new Error();
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
}
|
|
never2(): never {
|
|
>never2 : Symbol(C.never2, Decl(neverType.ts, 60, 5))
|
|
|
|
while (true) {}
|
|
}
|
|
}
|
|
|
|
function f1(x: string | number) {
|
|
>f1 : Symbol(f1, Decl(neverType.ts, 64, 1))
|
|
>x : Symbol(x, Decl(neverType.ts, 66, 12))
|
|
|
|
if (typeof x === "boolean") {
|
|
>x : Symbol(x, Decl(neverType.ts, 66, 12))
|
|
|
|
x; // never
|
|
>x : Symbol(x, Decl(neverType.ts, 66, 12))
|
|
}
|
|
}
|
|
|
|
function f2(x: string | number) {
|
|
>f2 : Symbol(f2, Decl(neverType.ts, 70, 1))
|
|
>x : Symbol(x, Decl(neverType.ts, 72, 12))
|
|
|
|
while (true) {
|
|
if (typeof x === "boolean") {
|
|
>x : Symbol(x, Decl(neverType.ts, 72, 12))
|
|
|
|
return x; // never
|
|
>x : Symbol(x, Decl(neverType.ts, 72, 12))
|
|
}
|
|
}
|
|
}
|
|
|
|
function test(cb: () => string) {
|
|
>test : Symbol(test, Decl(neverType.ts, 78, 1))
|
|
>cb : Symbol(cb, Decl(neverType.ts, 80, 14))
|
|
|
|
let s = cb();
|
|
>s : Symbol(s, Decl(neverType.ts, 81, 7))
|
|
>cb : Symbol(cb, Decl(neverType.ts, 80, 14))
|
|
|
|
return s;
|
|
>s : Symbol(s, Decl(neverType.ts, 81, 7))
|
|
}
|
|
|
|
let errorCallback = () => error("Error callback");
|
|
>errorCallback : Symbol(errorCallback, Decl(neverType.ts, 85, 3))
|
|
>error : Symbol(error, Decl(neverType.ts, 0, 0))
|
|
|
|
test(() => "hello");
|
|
>test : Symbol(test, Decl(neverType.ts, 78, 1))
|
|
|
|
test(() => fail());
|
|
>test : Symbol(test, Decl(neverType.ts, 78, 1))
|
|
>fail : Symbol(fail, Decl(neverType.ts, 8, 1))
|
|
|
|
test(() => { throw new Error(); })
|
|
>test : Symbol(test, Decl(neverType.ts, 78, 1))
|
|
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
|
|
|
test(errorCallback);
|
|
>test : Symbol(test, Decl(neverType.ts, 78, 1))
|
|
>errorCallback : Symbol(errorCallback, Decl(neverType.ts, 85, 3))
|
|
|