-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathnarrowingTypeofFunction.types
More file actions
60 lines (50 loc) · 1.41 KB
/
narrowingTypeofFunction.types
File metadata and controls
60 lines (50 loc) · 1.41 KB
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
=== tests/cases/compiler/narrowingTypeofFunction.ts ===
type Meta = { foo: string }
>Meta : Meta
>foo : string
interface F { (): string }
function f1(a: (F & Meta) | string) {
>f1 : (a: (F & Meta) | string) => void
>a : string | (F & Meta)
if (typeof a === "function") {
>typeof a === "function" : boolean
>typeof a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>a : string | (F & Meta)
>"function" : "function"
a;
>a : F & Meta
}
else {
a;
>a : string
}
}
function f2<T>(x: (T & F) | T & string) {
>f2 : <T>(x: (T & F) | (T & string)) => void
>x : (T & F) | (T & string)
if (typeof x === "function") {
>typeof x === "function" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : (T & F) | (T & string)
>"function" : "function"
x;
>x : (T & F) | (T & string)
}
else {
x;
>x : T & string
}
}
function f3(x: { _foo: number } & number) {
>f3 : (x: { _foo: number;} & number) => void
>x : { _foo: number; } & number
>_foo : number
if (typeof x === "function") {
>typeof x === "function" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : { _foo: number; } & number
>"function" : "function"
x;
>x : never
}
}