File: booleanLiteralsContextuallyTypedFromUnion.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 (132 lines) | stat: -rw-r--r-- 3,903 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
=== tests/cases/compiler/booleanLiteralsContextuallyTypedFromUnion.tsx ===
interface A { isIt: true; text: string; }
>isIt : true
>true : true
>text : string

interface B { isIt: false; value: number; }
>isIt : false
>false : false
>value : number

type C = A | B;
>C : C

const isIt = Math.random() > 0.5;
>isIt : boolean
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
>Math : Math
>random : () => number
>0.5 : 0.5

const c: C = isIt ? { isIt, text: 'hey' } : { isIt, value: 123 };
>c : C
>isIt ? { isIt, text: 'hey' } : { isIt, value: 123 } : { isIt: true; text: string; } | { isIt: false; value: number; }
>isIt : boolean
>{ isIt, text: 'hey' } : { isIt: true; text: string; }
>isIt : true
>text : string
>'hey' : "hey"
>{ isIt, value: 123 } : { isIt: false; value: number; }
>isIt : false
>value : number
>123 : 123

const cc: C = isIt ? { isIt: isIt, text: 'hey' } : { isIt: isIt, value: 123 };
>cc : C
>isIt ? { isIt: isIt, text: 'hey' } : { isIt: isIt, value: 123 } : { isIt: true; text: string; } | { isIt: false; value: number; }
>isIt : boolean
>{ isIt: isIt, text: 'hey' } : { isIt: true; text: string; }
>isIt : true
>isIt : true
>text : string
>'hey' : "hey"
>{ isIt: isIt, value: 123 } : { isIt: false; value: number; }
>isIt : false
>isIt : false
>value : number
>123 : 123

type ComponentProps =
>ComponentProps : ComponentProps

    | {
        optionalBool: true;
>optionalBool : true
>true : true

        mandatoryFn: () => void;
>mandatoryFn : () => void
    }
    | {
        optionalBool: false;
>optionalBool : false
>false : false

    };

let Funk = (_props: ComponentProps) => <div>Hello</div>;
>Funk : (_props: ComponentProps) => JSX.Element
>(_props: ComponentProps) => <div>Hello</div> : (_props: ComponentProps) => JSX.Element
>_props : ComponentProps
><div>Hello</div> : JSX.Element
>div : any
>div : any

let Fail1 = () => <Funk mandatoryFn={() => { }} optionalBool={true} />
>Fail1 : () => JSX.Element
>() => <Funk mandatoryFn={() => { }} optionalBool={true} /> : () => JSX.Element
><Funk mandatoryFn={() => { }} optionalBool={true} /> : JSX.Element
>Funk : (_props: ComponentProps) => JSX.Element
>mandatoryFn : () => void
>() => { } : () => void
>optionalBool : true
>true : true

let Fail2 = () => <Funk mandatoryFn={() => { }} optionalBool={true as true} />
>Fail2 : () => JSX.Element
>() => <Funk mandatoryFn={() => { }} optionalBool={true as true} /> : () => JSX.Element
><Funk mandatoryFn={() => { }} optionalBool={true as true} /> : JSX.Element
>Funk : (_props: ComponentProps) => JSX.Element
>mandatoryFn : () => void
>() => { } : () => void
>optionalBool : true
>true as true : true
>true : true
>true : true

let True = true as true;
>True : true
>true as true : true
>true : true
>true : true

let Fail3 = () => <Funk mandatoryFn={() => { }} optionalBool={True} />
>Fail3 : () => JSX.Element
>() => <Funk mandatoryFn={() => { }} optionalBool={True} /> : () => JSX.Element
><Funk mandatoryFn={() => { }} optionalBool={True} /> : JSX.Element
>Funk : (_props: ComponentProps) => JSX.Element
>mandatoryFn : () => void
>() => { } : () => void
>optionalBool : true
>True : true

let attrs2 = { optionalBool: true as true, mandatoryFn: () => { } }
>attrs2 : { optionalBool: true; mandatoryFn: () => void; }
>{ optionalBool: true as true, mandatoryFn: () => { } } : { optionalBool: true; mandatoryFn: () => void; }
>optionalBool : true
>true as true : true
>true : true
>true : true
>mandatoryFn : () => void
>() => { } : () => void

let Success = () => <Funk {...attrs2} />
>Success : () => JSX.Element
>() => <Funk {...attrs2} /> : () => JSX.Element
><Funk {...attrs2} /> : JSX.Element
>Funk : (_props: ComponentProps) => JSX.Element
>attrs2 : { optionalBool: true; mandatoryFn: () => void; }