Skip to content

Commit 6774f90

Browse files
committed
add unparenthesizedFunctionTypeInUnionOrIntersection test
1 parent eb231ba commit 6774f90

5 files changed

+291
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(1,19): error TS1385: Function type notation must be parenthesized when used in a union type.
2+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(2,19): error TS1385: Function type notation must be parenthesized when used in a union type.
3+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(3,12): error TS1385: Function type notation must be parenthesized when used in a union type.
4+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(4,12): error TS1385: Function type notation must be parenthesized when used in a union type.
5+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(5,19): error TS1385: Function type notation must be parenthesized when used in a union type.
6+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(8,4): error TS1385: Function type notation must be parenthesized when used in a union type.
7+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(11,19): error TS1387: Function type notation must be parenthesized when used in an intersection type.
8+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(12,19): error TS1387: Function type notation must be parenthesized when used in an intersection type.
9+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(13,12): error TS1387: Function type notation must be parenthesized when used in an intersection type.
10+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(14,12): error TS1387: Function type notation must be parenthesized when used in an intersection type.
11+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(15,19): error TS1387: Function type notation must be parenthesized when used in an intersection type.
12+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(18,4): error TS1387: Function type notation must be parenthesized when used in an intersection type.
13+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(20,37): error TS1385: Function type notation must be parenthesized when used in a union type.
14+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(21,31): error TS1387: Function type notation must be parenthesized when used in an intersection type.
15+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(22,16): error TS1387: Function type notation must be parenthesized when used in an intersection type.
16+
tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts(22,37): error TS1385: Function type notation must be parenthesized when used in a union type.
17+
18+
19+
==== tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts (16 errors) ====
20+
type U1 = string | () => void;
21+
~~~~~~~~~~~
22+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
23+
type U2 = string | (foo: number) => void
24+
~~~~~~~~~~~~~~~~~~~~~~
25+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
26+
type U3 = | () => number
27+
~~~~~~~~~~~~~
28+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
29+
type U4 = | (foo?: number) => void;
30+
~~~~~~~~~~~~~~~~~~~~~~~
31+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
32+
type U5 = string | (number: number, foo?: string) => void | number;
33+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
35+
type U6 =
36+
| string
37+
| (...args: any[]) => void
38+
~~~~~~~~~~~~~~~~~~~~~~~~~
39+
| number;
40+
~~~~~~~~~~
41+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
42+
43+
type I1 = string & () => void;
44+
~~~~~~~~~~~
45+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
46+
type I2 = string & (...foo: number[]) => void;
47+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
49+
type I3 = & () => boolean
50+
~~~~~~~~~~~~~~
51+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
52+
type I4 = & () => boolean & null;
53+
~~~~~~~~~~~~~~~~~~~~~
54+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
55+
type I5 = string & (any: any, any2: any) => any & any;
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
58+
type I6 =
59+
& string
60+
& (foo: any) => void;
61+
~~~~~~~~~~~~~~~~~~~
62+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
63+
64+
type M1 = string | number & string | () => number;
65+
~~~~~~~~~~~~~
66+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
67+
type M2 = any & string | any & () => void;
68+
~~~~~~~~~~~
69+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
70+
type M3 = any & (foo: any) => void | () => void & any;
71+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
!!! error TS1387: Function type notation must be parenthesized when used in an intersection type.
73+
~~~~~~~~~~~~~~~~~
74+
!!! error TS1385: Function type notation must be parenthesized when used in a union type.
75+
76+
type OK1 = string | (number);
77+
type OK2 = string | ((number));
78+
type OK3 = string | (()=> void);
79+
type OK4 = string | (()=> string | number);
80+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [unparenthesizedFunctionTypeInUnionOrIntersection.ts]
2+
type U1 = string | () => void;
3+
type U2 = string | (foo: number) => void
4+
type U3 = | () => number
5+
type U4 = | (foo?: number) => void;
6+
type U5 = string | (number: number, foo?: string) => void | number;
7+
type U6 =
8+
| string
9+
| (...args: any[]) => void
10+
| number;
11+
12+
type I1 = string & () => void;
13+
type I2 = string & (...foo: number[]) => void;
14+
type I3 = & () => boolean
15+
type I4 = & () => boolean & null;
16+
type I5 = string & (any: any, any2: any) => any & any;
17+
type I6 =
18+
& string
19+
& (foo: any) => void;
20+
21+
type M1 = string | number & string | () => number;
22+
type M2 = any & string | any & () => void;
23+
type M3 = any & (foo: any) => void | () => void & any;
24+
25+
type OK1 = string | (number);
26+
type OK2 = string | ((number));
27+
type OK3 = string | (()=> void);
28+
type OK4 = string | (()=> string | number);
29+
30+
31+
//// [unparenthesizedFunctionTypeInUnionOrIntersection.js]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
=== tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts ===
2+
type U1 = string | () => void;
3+
>U1 : Symbol(U1, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 0, 0))
4+
5+
type U2 = string | (foo: number) => void
6+
>U2 : Symbol(U2, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 0, 30))
7+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 1, 20))
8+
9+
type U3 = | () => number
10+
>U3 : Symbol(U3, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 1, 40))
11+
12+
type U4 = | (foo?: number) => void;
13+
>U4 : Symbol(U4, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 2, 24))
14+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 3, 13))
15+
16+
type U5 = string | (number: number, foo?: string) => void | number;
17+
>U5 : Symbol(U5, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 3, 35))
18+
>number : Symbol(number, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 4, 20))
19+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 4, 35))
20+
21+
type U6 =
22+
>U6 : Symbol(U6, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 4, 67))
23+
24+
| string
25+
| (...args: any[]) => void
26+
>args : Symbol(args, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 7, 5))
27+
28+
| number;
29+
30+
type I1 = string & () => void;
31+
>I1 : Symbol(I1, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 8, 11))
32+
33+
type I2 = string & (...foo: number[]) => void;
34+
>I2 : Symbol(I2, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 10, 30))
35+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 11, 20))
36+
37+
type I3 = & () => boolean
38+
>I3 : Symbol(I3, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 11, 46))
39+
40+
type I4 = & () => boolean & null;
41+
>I4 : Symbol(I4, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 12, 25))
42+
43+
type I5 = string & (any: any, any2: any) => any & any;
44+
>I5 : Symbol(I5, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 13, 33))
45+
>any : Symbol(any, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 14, 20))
46+
>any2 : Symbol(any2, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 14, 29))
47+
48+
type I6 =
49+
>I6 : Symbol(I6, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 14, 54))
50+
51+
& string
52+
& (foo: any) => void;
53+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 17, 5))
54+
55+
type M1 = string | number & string | () => number;
56+
>M1 : Symbol(M1, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 17, 23))
57+
58+
type M2 = any & string | any & () => void;
59+
>M2 : Symbol(M2, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 19, 50))
60+
61+
type M3 = any & (foo: any) => void | () => void & any;
62+
>M3 : Symbol(M3, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 20, 42))
63+
>foo : Symbol(foo, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 21, 17))
64+
65+
type OK1 = string | (number);
66+
>OK1 : Symbol(OK1, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 21, 54))
67+
68+
type OK2 = string | ((number));
69+
>OK2 : Symbol(OK2, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 23, 29))
70+
71+
type OK3 = string | (()=> void);
72+
>OK3 : Symbol(OK3, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 24, 31))
73+
74+
type OK4 = string | (()=> string | number);
75+
>OK4 : Symbol(OK4, Decl(unparenthesizedFunctionTypeInUnionOrIntersection.ts, 25, 32))
76+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
=== tests/cases/compiler/unparenthesizedFunctionTypeInUnionOrIntersection.ts ===
2+
type U1 = string | () => void;
3+
>U1 : U1
4+
5+
type U2 = string | (foo: number) => void
6+
>U2 : U2
7+
>foo : number
8+
9+
type U3 = | () => number
10+
>U3 : () => number
11+
12+
type U4 = | (foo?: number) => void;
13+
>U4 : (foo?: number) => void
14+
>foo : number
15+
16+
type U5 = string | (number: number, foo?: string) => void | number;
17+
>U5 : U5
18+
>number : number
19+
>foo : string
20+
21+
type U6 =
22+
>U6 : U6
23+
24+
| string
25+
| (...args: any[]) => void
26+
>args : any[]
27+
28+
| number;
29+
30+
type I1 = string & () => void;
31+
>I1 : I1
32+
33+
type I2 = string & (...foo: number[]) => void;
34+
>I2 : I2
35+
>foo : number[]
36+
37+
type I3 = & () => boolean
38+
>I3 : () => boolean
39+
40+
type I4 = & () => boolean & null;
41+
>I4 : () => boolean & null
42+
>null : null
43+
44+
type I5 = string & (any: any, any2: any) => any & any;
45+
>I5 : I5
46+
>any : any
47+
>any2 : any
48+
49+
type I6 =
50+
>I6 : I6
51+
52+
& string
53+
& (foo: any) => void;
54+
>foo : any
55+
56+
type M1 = string | number & string | () => number;
57+
>M1 : M1
58+
59+
type M2 = any & string | any & () => void;
60+
>M2 : any
61+
62+
type M3 = any & (foo: any) => void | () => void & any;
63+
>M3 : any
64+
>foo : any
65+
66+
type OK1 = string | (number);
67+
>OK1 : OK1
68+
69+
type OK2 = string | ((number));
70+
>OK2 : OK1
71+
72+
type OK3 = string | (()=> void);
73+
>OK3 : OK3
74+
75+
type OK4 = string | (()=> string | number);
76+
>OK4 : OK4
77+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type U1 = string | () => void;
2+
type U2 = string | (foo: number) => void
3+
type U3 = | () => number
4+
type U4 = | (foo?: number) => void;
5+
type U5 = string | (number: number, foo?: string) => void | number;
6+
type U6 =
7+
| string
8+
| (...args: any[]) => void
9+
| number;
10+
11+
type I1 = string & () => void;
12+
type I2 = string & (...foo: number[]) => void;
13+
type I3 = & () => boolean
14+
type I4 = & () => boolean & null;
15+
type I5 = string & (any: any, any2: any) => any & any;
16+
type I6 =
17+
& string
18+
& (foo: any) => void;
19+
20+
type M1 = string | number & string | () => number;
21+
type M2 = any & string | any & () => void;
22+
type M3 = any & (foo: any) => void | () => void & any;
23+
24+
type OK1 = string | (number);
25+
type OK2 = string | ((number));
26+
type OK3 = string | (()=> void);
27+
type OK4 = string | (()=> string | number);

0 commit comments

Comments
 (0)