File: narrowingIntersection.symbols

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (63 lines) | stat: -rw-r--r-- 2,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
=== 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))
    }
}