Skip to content

Commit d0e385e

Browse files
committed
add union type test to baselines
1 parent 101df93 commit d0e385e

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

tests/baselines/reference/inferTypePredicates.errors.txt

+9
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,13 @@ inferTypePredicates.ts(205,7): error TS2741: Property 'z' is missing in type 'C1
275275
} else {
276276
let t: never = str; // should OK
277277
}
278+
279+
// infer a union type
280+
function isNumOrStr(x: unknown) {
281+
return (typeof x === "number" || typeof x === "string");
282+
}
283+
declare let unk: unknown;
284+
if (isNumOrStr(unk)) {
285+
let t: number | string = unk; // should ok
286+
}
278287

tests/baselines/reference/inferTypePredicates.js

+16
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ if (isStringFromUnknown(str)) {
232232
} else {
233233
let t: never = str; // should OK
234234
}
235+
236+
// infer a union type
237+
function isNumOrStr(x: unknown) {
238+
return (typeof x === "number" || typeof x === "string");
239+
}
240+
declare let unk: unknown;
241+
if (isNumOrStr(unk)) {
242+
let t: number | string = unk; // should ok
243+
}
235244

236245

237246
//// [inferTypePredicates.js]
@@ -443,3 +452,10 @@ if (isStringFromUnknown(str)) {
443452
else {
444453
var t = str; // should OK
445454
}
455+
// infer a union type
456+
function isNumOrStr(x) {
457+
return (typeof x === "number" || typeof x === "string");
458+
}
459+
if (isNumOrStr(unk)) {
460+
var t = unk; // should ok
461+
}

tests/baselines/reference/inferTypePredicates.symbols

+21
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,24 @@ if (isStringFromUnknown(str)) {
659659
>str : Symbol(str, Decl(inferTypePredicates.ts, 216, 11))
660660
}
661661

662+
// infer a union type
663+
function isNumOrStr(x: unknown) {
664+
>isNumOrStr : Symbol(isNumOrStr, Decl(inferTypePredicates.ts, 230, 1))
665+
>x : Symbol(x, Decl(inferTypePredicates.ts, 233, 20))
666+
667+
return (typeof x === "number" || typeof x === "string");
668+
>x : Symbol(x, Decl(inferTypePredicates.ts, 233, 20))
669+
>x : Symbol(x, Decl(inferTypePredicates.ts, 233, 20))
670+
}
671+
declare let unk: unknown;
672+
>unk : Symbol(unk, Decl(inferTypePredicates.ts, 236, 11))
673+
674+
if (isNumOrStr(unk)) {
675+
>isNumOrStr : Symbol(isNumOrStr, Decl(inferTypePredicates.ts, 230, 1))
676+
>unk : Symbol(unk, Decl(inferTypePredicates.ts, 236, 11))
677+
678+
let t: number | string = unk; // should ok
679+
>t : Symbol(t, Decl(inferTypePredicates.ts, 238, 5))
680+
>unk : Symbol(unk, Decl(inferTypePredicates.ts, 236, 11))
681+
}
682+

tests/baselines/reference/inferTypePredicates.types

+30
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,33 @@ if (isStringFromUnknown(str)) {
854854
>str : never
855855
}
856856

857+
// infer a union type
858+
function isNumOrStr(x: unknown) {
859+
>isNumOrStr : (x: unknown) => x is string | number
860+
>x : unknown
861+
862+
return (typeof x === "number" || typeof x === "string");
863+
>(typeof x === "number" || typeof x === "string") : boolean
864+
>typeof x === "number" || typeof x === "string" : boolean
865+
>typeof x === "number" : boolean
866+
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
867+
>x : unknown
868+
>"number" : "number"
869+
>typeof x === "string" : boolean
870+
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
871+
>x : unknown
872+
>"string" : "string"
873+
}
874+
declare let unk: unknown;
875+
>unk : unknown
876+
877+
if (isNumOrStr(unk)) {
878+
>isNumOrStr(unk) : boolean
879+
>isNumOrStr : (x: unknown) => x is string | number
880+
>unk : unknown
881+
882+
let t: number | string = unk; // should ok
883+
>t : string | number
884+
>unk : string | number
885+
}
886+

0 commit comments

Comments
 (0)