File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed
tests/cases/conformance/expressions/typeGuards Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ function f1 ( x : any ) {
3
+ if ( typeof x === "function" ) {
4
+ x ; // any
5
+ }
6
+ }
7
+
8
+ function f2 ( x : unknown ) {
9
+ if ( typeof x === "function" ) {
10
+ x ; // Function
11
+ }
12
+ }
13
+
14
+ function f3 ( x : { } ) {
15
+ if ( typeof x === "function" ) {
16
+ x ; // Function
17
+ }
18
+ }
19
+
20
+ function f4 < T > ( x : T ) {
21
+ if ( typeof x === "function" ) {
22
+ x ; // T & Function
23
+ }
24
+ }
25
+
26
+ function f5 ( x : { s : string } ) {
27
+ if ( typeof x === "function" ) {
28
+ x ; // never
29
+ }
30
+ }
31
+
32
+ function f6 ( x : ( ) => string ) {
33
+ if ( typeof x === "function" ) {
34
+ x ; // () => string
35
+ }
36
+ }
37
+
38
+ function f10 ( x : string | ( ( ) => string ) ) {
39
+ if ( typeof x === "function" ) {
40
+ x ; // () => string
41
+ }
42
+ else {
43
+ x ; // string
44
+ }
45
+ }
46
+
47
+ function f11 ( x : { s : string } | ( ( ) => string ) ) {
48
+ if ( typeof x === "function" ) {
49
+ x ; // () => string
50
+ }
51
+ else {
52
+ x ; // { s: string }
53
+ }
54
+ }
55
+
56
+ function f12 ( x : { s : string } | { n : number } ) {
57
+ if ( typeof x === "function" ) {
58
+ x ; // never
59
+ }
60
+ else {
61
+ x ; // { s: string } | { n: number }
62
+ }
63
+ }
64
+
65
+ // Repro from #18238
66
+
67
+ function f100 < T , K extends keyof T > ( obj : T , keys : K [ ] ) : void {
68
+ for ( const k of keys ) {
69
+ const item = obj [ k ] ;
70
+ if ( typeof item == 'function' )
71
+ item . call ( obj ) ;
72
+ }
73
+ }
You can’t perform that action at this time.
0 commit comments