TypeScript/tests/baselines/reference/narrowingIntersection.symbols
2021-08-02 16:12:09 -07:00

64 lines
2.9 KiB
Plaintext

=== tests/cases/compiler/narrowingIntersection.ts ===
// Somehow this being an intersection matters.
type FooAndBaz = { foo: unknown } & { baz: unknown };
>FooAndBaz : Symbol(FooAndBaz, Decl(narrowingIntersection.ts, 0, 0))
>foo : Symbol(foo, Decl(narrowingIntersection.ts, 1, 18))
>baz : Symbol(baz, Decl(narrowingIntersection.ts, 1, 37))
type Disjoint =
>Disjoint : Symbol(Disjoint, Decl(narrowingIntersection.ts, 1, 53))
| { readonly value: string; readonly err?: never; }
>value : Symbol(value, Decl(narrowingIntersection.ts, 4, 4))
>err : Symbol(err, Decl(narrowingIntersection.ts, 4, 28))
| { readonly value?: never; readonly err: FooAndBaz; };
>value : Symbol(value, Decl(narrowingIntersection.ts, 5, 4))
>err : Symbol(err, Decl(narrowingIntersection.ts, 5, 28))
>FooAndBaz : Symbol(FooAndBaz, Decl(narrowingIntersection.ts, 0, 0))
function test1(result: Disjoint): string {
>test1 : Symbol(test1, Decl(narrowingIntersection.ts, 5, 56))
>result : Symbol(result, Decl(narrowingIntersection.ts, 7, 15))
>Disjoint : Symbol(Disjoint, Decl(narrowingIntersection.ts, 1, 53))
if (result.err) {
>result.err : Symbol(err, Decl(narrowingIntersection.ts, 4, 28), Decl(narrowingIntersection.ts, 5, 28))
>result : Symbol(result, Decl(narrowingIntersection.ts, 7, 15))
>err : Symbol(err, Decl(narrowingIntersection.ts, 4, 28), Decl(narrowingIntersection.ts, 5, 28))
throw result.err;
>result.err : Symbol(err, Decl(narrowingIntersection.ts, 4, 28), Decl(narrowingIntersection.ts, 5, 28))
>result : Symbol(result, Decl(narrowingIntersection.ts, 7, 15))
>err : Symbol(err, Decl(narrowingIntersection.ts, 4, 28), Decl(narrowingIntersection.ts, 5, 28))
}
// Error, should OK
return result.value;
>result.value : Symbol(value, Decl(narrowingIntersection.ts, 4, 4), Decl(narrowingIntersection.ts, 5, 4))
>result : Symbol(result, Decl(narrowingIntersection.ts, 7, 15))
>value : Symbol(value, Decl(narrowingIntersection.ts, 4, 4), Decl(narrowingIntersection.ts, 5, 4))
}
type TrivialIntersection = { a: 1 } & { a: 1 };
>TrivialIntersection : Symbol(TrivialIntersection, Decl(narrowingIntersection.ts, 13, 1))
>a : Symbol(a, Decl(narrowingIntersection.ts, 15, 28))
>a : Symbol(a, Decl(narrowingIntersection.ts, 15, 39))
function want0(x: 0) {}
>want0 : Symbol(want0, Decl(narrowingIntersection.ts, 15, 47))
>x : Symbol(x, Decl(narrowingIntersection.ts, 17, 15))
function test2(a: 0 | TrivialIntersection) {
>test2 : Symbol(test2, Decl(narrowingIntersection.ts, 17, 23))
>a : Symbol(a, Decl(narrowingIntersection.ts, 19, 15))
>TrivialIntersection : Symbol(TrivialIntersection, Decl(narrowingIntersection.ts, 13, 1))
if (a === 0) {
>a : Symbol(a, Decl(narrowingIntersection.ts, 19, 15))
want0(a); // Fails, but expect to work
>want0 : Symbol(want0, Decl(narrowingIntersection.ts, 15, 47))
>a : Symbol(a, Decl(narrowingIntersection.ts, 19, 15))
}
}