We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 101df93 commit d0e385eCopy full SHA for d0e385e
4 files changed
tests/baselines/reference/inferTypePredicates.errors.txt
@@ -275,4 +275,13 @@ inferTypePredicates.ts(205,7): error TS2741: Property 'z' is missing in type 'C1
275
} else {
276
let t: never = str; // should OK
277
}
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
287
tests/baselines/reference/inferTypePredicates.js
@@ -232,6 +232,15 @@ if (isStringFromUnknown(str)) {
232
233
234
235
236
+// infer a union type
237
+function isNumOrStr(x: unknown) {
238
239
+}
240
+declare let unk: unknown;
241
+if (isNumOrStr(unk)) {
242
243
244
245
246
//// [inferTypePredicates.js]
@@ -443,3 +452,10 @@ if (isStringFromUnknown(str)) {
443
452
else {
444
453
var t = str; // should OK
445
454
455
456
+function isNumOrStr(x) {
457
458
459
460
+ var t = unk; // should ok
461
tests/baselines/reference/inferTypePredicates.symbols
@@ -659,3 +659,24 @@ if (isStringFromUnknown(str)) {
659
>str : Symbol(str, Decl(inferTypePredicates.ts, 216, 11))
660
661
662
663
664
+>isNumOrStr : Symbol(isNumOrStr, Decl(inferTypePredicates.ts, 230, 1))
665
+>x : Symbol(x, Decl(inferTypePredicates.ts, 233, 20))
666
667
668
669
670
671
672
+>unk : Symbol(unk, Decl(inferTypePredicates.ts, 236, 11))
673
674
675
676
677
678
679
+>t : Symbol(t, Decl(inferTypePredicates.ts, 238, 5))
680
681
682
tests/baselines/reference/inferTypePredicates.types
@@ -854,3 +854,33 @@ if (isStringFromUnknown(str)) {
854
>str : never
855
856
857
858
859
+>isNumOrStr : (x: unknown) => x is string | number
860
+>x : unknown
861
862
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
868
+>"number" : "number"
869
+>typeof x === "string" : boolean
870
871
872
+>"string" : "string"
873
874
875
+>unk : unknown
876
877
878
+>isNumOrStr(unk) : boolean
879
880
881
882
883
+>t : string | number
884
+>unk : string | number
885
886
0 commit comments