File: controlFlowDestructuringLoop.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (61 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
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
=== tests/cases/compiler/controlFlowDestructuringLoop.ts ===
// Repro from #28758

interface NumVal { val: number; }
>val : number

interface StrVal { val: string; }
>val : string

type Val = NumVal | StrVal;
>Val : Val

function isNumVal(x: Val): x is NumVal {
>isNumVal : (x: Val) => x is NumVal
>x : Val

    return typeof x.val === 'number';
>typeof x.val === 'number' : boolean
>typeof x.val : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x.val : string | number
>x : Val
>val : string | number
>'number' : "number"
}

function foo(things: Val[]): void {
>foo : (things: Val[]) => void
>things : Val[]

    for (const thing of things) {
>thing : Val
>things : Val[]

        if (isNumVal(thing)) {
>isNumVal(thing) : boolean
>isNumVal : (x: Val) => x is NumVal
>thing : Val

            const { val } = thing;
>val : number
>thing : NumVal

            val.toFixed(2);
>val.toFixed(2) : string
>val.toFixed : (fractionDigits?: number | undefined) => string
>val : number
>toFixed : (fractionDigits?: number | undefined) => string
>2 : 2
        }
        else {
            const { val } = thing;
>val : string
>thing : StrVal

            val.length;
>val.length : number
>val : string
>length : number
        }
    }
}