Skip to content

Commit 50ab58c

Browse files
committed
add unparenthesizedConstructorTypeInUnionOrIntersection test
1 parent 6774f90 commit 50ab58c

5 files changed

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

0 commit comments

Comments
 (0)