Skip to content

Commit b6a6c78

Browse files
committed
Add regression test
1 parent 5f6af5a commit b6a6c78

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
noCrashOnMixin2.ts(11,33): error TS2370: A rest parameter must be of an array type.
2+
noCrashOnMixin2.ts(11,40): error TS1047: A rest parameter cannot be optional.
3+
noCrashOnMixin2.ts(14,12): error TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'.
4+
noCrashOnMixin2.ts(23,9): error TS2674: Constructor of class 'Abstract' is protected and only accessible within the class declaration.
5+
6+
7+
==== noCrashOnMixin2.ts (4 errors) ====
8+
// https://github.com/microsoft/TypeScript/issues/62921
9+
10+
class Abstract {
11+
protected constructor() {
12+
}
13+
}
14+
15+
class Concrete extends Abstract {
16+
}
17+
18+
type Constructor<T = {}> = new (...args?: any[]) => T;
19+
~~~~~~~~~~~~~~~
20+
!!! error TS2370: A rest parameter must be of an array type.
21+
~
22+
!!! error TS1047: A rest parameter cannot be optional.
23+
24+
function Mixin<TBase extends Constructor>(Base: TBase) {
25+
return class extends Base {
26+
~~~~~
27+
!!! error TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'.
28+
};
29+
}
30+
31+
class Empty {
32+
}
33+
34+
class CrashTrigger extends Mixin(Empty) {
35+
public trigger() {
36+
new Concrete();
37+
~~~~~~~~~~~~~~
38+
!!! error TS2674: Constructor of class 'Abstract' is protected and only accessible within the class declaration.
39+
}
40+
}
41+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [tests/cases/compiler/noCrashOnMixin2.ts] ////
2+
3+
=== noCrashOnMixin2.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/62921
5+
6+
class Abstract {
7+
>Abstract : Symbol(Abstract, Decl(noCrashOnMixin2.ts, 0, 0))
8+
9+
protected constructor() {
10+
}
11+
}
12+
13+
class Concrete extends Abstract {
14+
>Concrete : Symbol(Concrete, Decl(noCrashOnMixin2.ts, 5, 1))
15+
>Abstract : Symbol(Abstract, Decl(noCrashOnMixin2.ts, 0, 0))
16+
}
17+
18+
type Constructor<T = {}> = new (...args?: any[]) => T;
19+
>Constructor : Symbol(Constructor, Decl(noCrashOnMixin2.ts, 8, 1))
20+
>T : Symbol(T, Decl(noCrashOnMixin2.ts, 10, 17))
21+
>args : Symbol(args, Decl(noCrashOnMixin2.ts, 10, 32))
22+
>T : Symbol(T, Decl(noCrashOnMixin2.ts, 10, 17))
23+
24+
function Mixin<TBase extends Constructor>(Base: TBase) {
25+
>Mixin : Symbol(Mixin, Decl(noCrashOnMixin2.ts, 10, 54))
26+
>TBase : Symbol(TBase, Decl(noCrashOnMixin2.ts, 12, 15))
27+
>Constructor : Symbol(Constructor, Decl(noCrashOnMixin2.ts, 8, 1))
28+
>Base : Symbol(Base, Decl(noCrashOnMixin2.ts, 12, 42))
29+
>TBase : Symbol(TBase, Decl(noCrashOnMixin2.ts, 12, 15))
30+
31+
return class extends Base {
32+
>Base : Symbol(Base, Decl(noCrashOnMixin2.ts, 12, 42))
33+
34+
};
35+
}
36+
37+
class Empty {
38+
>Empty : Symbol(Empty, Decl(noCrashOnMixin2.ts, 15, 1))
39+
}
40+
41+
class CrashTrigger extends Mixin(Empty) {
42+
>CrashTrigger : Symbol(CrashTrigger, Decl(noCrashOnMixin2.ts, 18, 1))
43+
>Mixin : Symbol(Mixin, Decl(noCrashOnMixin2.ts, 10, 54))
44+
>Empty : Symbol(Empty, Decl(noCrashOnMixin2.ts, 15, 1))
45+
46+
public trigger() {
47+
>trigger : Symbol(CrashTrigger.trigger, Decl(noCrashOnMixin2.ts, 20, 41))
48+
49+
new Concrete();
50+
>Concrete : Symbol(Concrete, Decl(noCrashOnMixin2.ts, 5, 1))
51+
}
52+
}
53+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//// [tests/cases/compiler/noCrashOnMixin2.ts] ////
2+
3+
=== noCrashOnMixin2.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/62921
5+
6+
class Abstract {
7+
>Abstract : Abstract
8+
> : ^^^^^^^^
9+
10+
protected constructor() {
11+
}
12+
}
13+
14+
class Concrete extends Abstract {
15+
>Concrete : Concrete
16+
> : ^^^^^^^^
17+
>Abstract : Abstract
18+
> : ^^^^^^^^
19+
}
20+
21+
type Constructor<T = {}> = new (...args?: any[]) => T;
22+
>Constructor : Constructor<T>
23+
> : ^^^^^^^^^^^^^^
24+
>args : any[] | undefined
25+
> : ^^^^^^^^^^^^^^^^^
26+
27+
function Mixin<TBase extends Constructor>(Base: TBase) {
28+
>Mixin : <TBase extends Constructor>(Base: TBase) => { new (...args?: any[]): (Anonymous class); prototype: Mixin<any>.(Anonymous class); } & TBase
29+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
>Base : TBase
31+
> : ^^^^^
32+
33+
return class extends Base {
34+
>class extends Base { } : { new (...args?: any[]): (Anonymous class); prototype: Mixin<any>.(Anonymous class); } & TBase
35+
> : ^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
>Base : {}
37+
> : ^^
38+
39+
};
40+
}
41+
42+
class Empty {
43+
>Empty : Empty
44+
> : ^^^^^
45+
}
46+
47+
class CrashTrigger extends Mixin(Empty) {
48+
>CrashTrigger : CrashTrigger
49+
> : ^^^^^^^^^^^^
50+
>Mixin(Empty) : Mixin<typeof Empty>.(Anonymous class)
51+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
>Mixin : <TBase extends Constructor>(Base: TBase) => { new (...args?: any[]): (Anonymous class); prototype: Mixin<any>.(Anonymous class); } & TBase
53+
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
>Empty : typeof Empty
55+
> : ^^^^^^^^^^^^
56+
57+
public trigger() {
58+
>trigger : () => void
59+
> : ^^^^^^^^^^
60+
61+
new Concrete();
62+
>new Concrete() : any
63+
> : ^^^
64+
>Concrete : typeof Concrete
65+
> : ^^^^^^^^^^^^^^^
66+
}
67+
}
68+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/62921
5+
6+
class Abstract {
7+
protected constructor() {
8+
}
9+
}
10+
11+
class Concrete extends Abstract {
12+
}
13+
14+
type Constructor<T = {}> = new (...args?: any[]) => T;
15+
16+
function Mixin<TBase extends Constructor>(Base: TBase) {
17+
return class extends Base {
18+
};
19+
}
20+
21+
class Empty {
22+
}
23+
24+
class CrashTrigger extends Mixin(Empty) {
25+
public trigger() {
26+
new Concrete();
27+
}
28+
}

0 commit comments

Comments
 (0)