File: genericCapturingFunctionNarrowing.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 (53 lines) | stat: -rw-r--r-- 3,361 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
=== tests/cases/compiler/genericCapturingFunctionNarrowing.ts ===
function needsToNarrowTheType<First extends { foo: string }, Second extends { bar: string }, SubFirst extends First, SubFirstMore extends First & {other: string}>(thing: First | SubFirst | SubFirstMore | Second) {
>needsToNarrowTheType : Symbol(needsToNarrowTheType, Decl(genericCapturingFunctionNarrowing.ts, 0, 0))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))
>foo : Symbol(foo, Decl(genericCapturingFunctionNarrowing.ts, 0, 45))
>Second : Symbol(Second, Decl(genericCapturingFunctionNarrowing.ts, 0, 60))
>bar : Symbol(bar, Decl(genericCapturingFunctionNarrowing.ts, 0, 77))
>SubFirst : Symbol(SubFirst, Decl(genericCapturingFunctionNarrowing.ts, 0, 92))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))
>SubFirstMore : Symbol(SubFirstMore, Decl(genericCapturingFunctionNarrowing.ts, 0, 116))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))
>other : Symbol(other, Decl(genericCapturingFunctionNarrowing.ts, 0, 147))
>thing : Symbol(thing, Decl(genericCapturingFunctionNarrowing.ts, 0, 163))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))
>SubFirst : Symbol(SubFirst, Decl(genericCapturingFunctionNarrowing.ts, 0, 92))
>SubFirstMore : Symbol(SubFirstMore, Decl(genericCapturingFunctionNarrowing.ts, 0, 116))
>Second : Symbol(Second, Decl(genericCapturingFunctionNarrowing.ts, 0, 60))

    if (hasAFoo(thing)) {
>hasAFoo : Symbol(hasAFoo, Decl(genericCapturingFunctionNarrowing.ts, 7, 5))
>thing : Symbol(thing, Decl(genericCapturingFunctionNarrowing.ts, 0, 163))

        console.log(thing.foo);
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>thing.foo : Symbol(foo, Decl(genericCapturingFunctionNarrowing.ts, 0, 45))
>thing : Symbol(thing, Decl(genericCapturingFunctionNarrowing.ts, 0, 163))
>foo : Symbol(foo, Decl(genericCapturingFunctionNarrowing.ts, 0, 45))
    }
    else {
        // I would expect this to work because the type should be narrowed in this branch to `Second`
        console.log(thing.bar); // Error: Property 'bar' does not exist on type 'First | Second'.
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>thing.bar : Symbol(bar, Decl(genericCapturingFunctionNarrowing.ts, 0, 77))
>thing : Symbol(thing, Decl(genericCapturingFunctionNarrowing.ts, 0, 163))
>bar : Symbol(bar, Decl(genericCapturingFunctionNarrowing.ts, 0, 77))
    }

    function hasAFoo(value: First | Second): value is First {
>hasAFoo : Symbol(hasAFoo, Decl(genericCapturingFunctionNarrowing.ts, 7, 5))
>value : Symbol(value, Decl(genericCapturingFunctionNarrowing.ts, 9, 21))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))
>Second : Symbol(Second, Decl(genericCapturingFunctionNarrowing.ts, 0, 60))
>value : Symbol(value, Decl(genericCapturingFunctionNarrowing.ts, 9, 21))
>First : Symbol(First, Decl(genericCapturingFunctionNarrowing.ts, 0, 30))

        return "foo" in value;
>value : Symbol(value, Decl(genericCapturingFunctionNarrowing.ts, 9, 21))
    }
}