Skip to content

Commit d3af9cf

Browse files
authored
Merge branch 'main' into fix/2426
2 parents 2080d09 + 1611cc9 commit d3af9cf

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed

internal/checker/checker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18556,6 +18556,9 @@ func findIndexInfo(indexInfos []*IndexInfo, keyType *Type) *IndexInfo {
1855618556
}
1855718557

1855818558
func (c *Checker) getBaseTypes(t *Type) []*Type {
18559+
if t.objectFlags&(ObjectFlagsClassOrInterface|ObjectFlagsReference) == 0 {
18560+
return nil
18561+
}
1855918562
data := t.AsInterfaceType()
1856018563
if !data.baseTypesResolved {
1856118564
if !c.pushTypeResolution(t, TypeSystemPropertyNameResolvedBaseTypes) {
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
protected constructor() {
10+
}
11+
}
12+
13+
class Concrete extends Abstract {
14+
>Concrete : Concrete
15+
>Abstract : Abstract
16+
}
17+
18+
type Constructor<T = {}> = new (...args?: any[]) => T;
19+
>Constructor : Constructor<T>
20+
>args : any[] | undefined
21+
22+
function Mixin<TBase extends Constructor>(Base: TBase) {
23+
>Mixin : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
24+
>Base : TBase
25+
26+
return class extends Base {
27+
>class extends Base { } : { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
28+
>Base : {}
29+
30+
};
31+
}
32+
33+
class Empty {
34+
>Empty : Empty
35+
}
36+
37+
class CrashTrigger extends Mixin(Empty) {
38+
>CrashTrigger : CrashTrigger
39+
>Mixin(Empty) : Mixin.(Anonymous class)
40+
>Mixin : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
41+
>Empty : typeof Empty
42+
43+
public trigger() {
44+
>trigger : () => void
45+
46+
new Concrete();
47+
>new Concrete() : Concrete
48+
>Concrete : typeof Concrete
49+
}
50+
}
51+
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)