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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
=== tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference1.ts ===
// Repro from #2264
interface Y { 'i am a very certain type': Y }
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
>'i am a very certain type' : Symbol(Y['i am a very certain type'], Decl(unionAndIntersectionInference1.ts, 2, 13))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
var y: Y = <Y>undefined;
>y : Symbol(y, Decl(unionAndIntersectionInference1.ts, 3, 3))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
>undefined : Symbol(undefined)
function destructure<a, r>(
>destructure : Symbol(destructure, Decl(unionAndIntersectionInference1.ts, 3, 24))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 4, 21))
>r : Symbol(r, Decl(unionAndIntersectionInference1.ts, 4, 23))
something: a | Y,
>something : Symbol(something, Decl(unionAndIntersectionInference1.ts, 4, 27))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 4, 21))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
haveValue: (value: a) => r,
>haveValue : Symbol(haveValue, Decl(unionAndIntersectionInference1.ts, 5, 21))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 6, 16))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 4, 21))
>r : Symbol(r, Decl(unionAndIntersectionInference1.ts, 4, 23))
haveY: (value: Y) => r
>haveY : Symbol(haveY, Decl(unionAndIntersectionInference1.ts, 6, 31))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 7, 12))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
>r : Symbol(r, Decl(unionAndIntersectionInference1.ts, 4, 23))
): r {
>r : Symbol(r, Decl(unionAndIntersectionInference1.ts, 4, 23))
return something === y ? haveY(y) : haveValue(<a>something);
>something : Symbol(something, Decl(unionAndIntersectionInference1.ts, 4, 27))
>y : Symbol(y, Decl(unionAndIntersectionInference1.ts, 3, 3))
>haveY : Symbol(haveY, Decl(unionAndIntersectionInference1.ts, 6, 31))
>y : Symbol(y, Decl(unionAndIntersectionInference1.ts, 3, 3))
>haveValue : Symbol(haveValue, Decl(unionAndIntersectionInference1.ts, 5, 21))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 4, 21))
>something : Symbol(something, Decl(unionAndIntersectionInference1.ts, 4, 27))
}
var value = Math.random() > 0.5 ? 'hey!' : <Y>undefined;
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 12, 3))
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Y : Symbol(Y, Decl(unionAndIntersectionInference1.ts, 0, 0))
>undefined : Symbol(undefined)
var result = destructure(value, text => 'string', y => 'other one'); // text: string, y: Y
>result : Symbol(result, Decl(unionAndIntersectionInference1.ts, 14, 3))
>destructure : Symbol(destructure, Decl(unionAndIntersectionInference1.ts, 3, 24))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 12, 3))
>text : Symbol(text, Decl(unionAndIntersectionInference1.ts, 14, 31))
>y : Symbol(y, Decl(unionAndIntersectionInference1.ts, 14, 49))
// Repro from #4212
function isVoid<a>(value: void | a): value is void {
>isVoid : Symbol(isVoid, Decl(unionAndIntersectionInference1.ts, 14, 68))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 18, 16))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 18, 19))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 18, 16))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 18, 19))
return undefined;
>undefined : Symbol(undefined)
}
function isNonVoid<a>(value: void | a) : value is a {
>isNonVoid : Symbol(isNonVoid, Decl(unionAndIntersectionInference1.ts, 20, 1))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 22, 19))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 22, 22))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 22, 19))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 22, 22))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 22, 19))
return undefined;
>undefined : Symbol(undefined)
}
function foo1<a>(value: void|a): void {
>foo1 : Symbol(foo1, Decl(unionAndIntersectionInference1.ts, 24, 1))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 26, 14))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 26, 17))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 26, 14))
if (isVoid(value)) {
>isVoid : Symbol(isVoid, Decl(unionAndIntersectionInference1.ts, 14, 68))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 26, 17))
value; // value is void
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 26, 17))
} else {
value; // value is a
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 26, 17))
}
}
function baz1<a>(value: void|a): void {
>baz1 : Symbol(baz1, Decl(unionAndIntersectionInference1.ts, 32, 1))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 34, 14))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 34, 17))
>a : Symbol(a, Decl(unionAndIntersectionInference1.ts, 34, 14))
if (isNonVoid(value)) {
>isNonVoid : Symbol(isNonVoid, Decl(unionAndIntersectionInference1.ts, 20, 1))
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 34, 17))
value; // value is a
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 34, 17))
} else {
value; // value is void
>value : Symbol(value, Decl(unionAndIntersectionInference1.ts, 34, 17))
}
}
// Repro from #5417
type Maybe<T> = T | void;
>Maybe : Symbol(Maybe, Decl(unionAndIntersectionInference1.ts, 40, 1))
>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 44, 11))
>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 44, 11))
function get<U>(x: U | void): U {
>get : Symbol(get, Decl(unionAndIntersectionInference1.ts, 44, 25))
>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 46, 13))
>x : Symbol(x, Decl(unionAndIntersectionInference1.ts, 46, 16))
>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 46, 13))
>U : Symbol(U, Decl(unionAndIntersectionInference1.ts, 46, 13))
return null; // just an example
}
let foo: Maybe<string>;
>foo : Symbol(foo, Decl(unionAndIntersectionInference1.ts, 50, 3))
>Maybe : Symbol(Maybe, Decl(unionAndIntersectionInference1.ts, 40, 1))
get(foo).toUpperCase(); // Ok
>get(foo).toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>get : Symbol(get, Decl(unionAndIntersectionInference1.ts, 44, 25))
>foo : Symbol(foo, Decl(unionAndIntersectionInference1.ts, 50, 3))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
// Repro from #5456
interface Man {
>Man : Symbol(Man, Decl(unionAndIntersectionInference1.ts, 51, 23))
walks: boolean;
>walks : Symbol(Man.walks, Decl(unionAndIntersectionInference1.ts, 55, 15))
}
interface Bear {
>Bear : Symbol(Bear, Decl(unionAndIntersectionInference1.ts, 57, 1))
roars: boolean;
>roars : Symbol(Bear.roars, Decl(unionAndIntersectionInference1.ts, 59, 16))
}
interface Pig {
>Pig : Symbol(Pig, Decl(unionAndIntersectionInference1.ts, 61, 1))
oinks: boolean;
>oinks : Symbol(Pig.oinks, Decl(unionAndIntersectionInference1.ts, 63, 15))
}
declare function pigify<T>(y: T & Bear): T & Pig;
>pigify : Symbol(pigify, Decl(unionAndIntersectionInference1.ts, 65, 1))
>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 67, 24))
>y : Symbol(y, Decl(unionAndIntersectionInference1.ts, 67, 27))
>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 67, 24))
>Bear : Symbol(Bear, Decl(unionAndIntersectionInference1.ts, 57, 1))
>T : Symbol(T, Decl(unionAndIntersectionInference1.ts, 67, 24))
>Pig : Symbol(Pig, Decl(unionAndIntersectionInference1.ts, 61, 1))
declare var mbp: Man & Bear;
>mbp : Symbol(mbp, Decl(unionAndIntersectionInference1.ts, 68, 11))
>Man : Symbol(Man, Decl(unionAndIntersectionInference1.ts, 51, 23))
>Bear : Symbol(Bear, Decl(unionAndIntersectionInference1.ts, 57, 1))
pigify(mbp).oinks; // OK, mbp is treated as Pig
>pigify(mbp).oinks : Symbol(Pig.oinks, Decl(unionAndIntersectionInference1.ts, 63, 15))
>pigify : Symbol(pigify, Decl(unionAndIntersectionInference1.ts, 65, 1))
>mbp : Symbol(mbp, Decl(unionAndIntersectionInference1.ts, 68, 11))
>oinks : Symbol(Pig.oinks, Decl(unionAndIntersectionInference1.ts, 63, 15))
pigify(mbp).walks; // Ok, mbp is treated as Man
>pigify(mbp).walks : Symbol(Man.walks, Decl(unionAndIntersectionInference1.ts, 55, 15))
>pigify : Symbol(pigify, Decl(unionAndIntersectionInference1.ts, 65, 1))
>mbp : Symbol(mbp, Decl(unionAndIntersectionInference1.ts, 68, 11))
>walks : Symbol(Man.walks, Decl(unionAndIntersectionInference1.ts, 55, 15))
|