1
1
// @declaration : true
2
2
3
- type Constructor < T > = new ( ...args : any [ ] ) => T ;
3
+ type Constructor < T = { } > = new ( ...args : any [ ] ) => T ;
4
4
5
5
class Base {
6
6
constructor ( public x : number , public y : number ) { }
@@ -16,47 +16,51 @@ interface Printable {
16
16
print ( ) : void ;
17
17
}
18
18
19
- const Printable = < T extends Constructor < Base > > ( superClass : T ) : Constructor < Printable > & { message : string } & T =>
19
+ const Printable = < T extends Constructor < Base > > (
20
+ superClass : T
21
+ ) : T & Constructor < Printable > & { message : string } =>
20
22
class extends superClass {
21
23
static message = "hello" ;
22
24
print ( ) {
23
- const output = this . x + "," + this . y ;
25
+ console . log ( this . x + "," + this . y ) ;
24
26
}
25
- }
27
+ } ;
26
28
27
29
interface Tagged {
28
30
_tag : string ;
29
31
}
30
32
31
- function Tagged < T extends Constructor < { } > > ( superClass : T ) : Constructor < Tagged > & T {
32
- class C extends superClass {
33
+ function Tagged < T extends Constructor < Base > > ( superClass : T ) : T & Constructor < Tagged > {
34
+ return class extends superClass {
33
35
_tag : string ;
34
36
constructor ( ...args : any [ ] ) {
35
37
super ( ...args ) ;
36
38
this . _tag = "hello" ;
37
39
}
38
- }
39
- return C ;
40
+ } ;
40
41
}
41
42
42
43
const Thing1 = Tagged ( Derived ) ;
43
- const Thing2 = Tagged ( Printable ( Derived ) ) ;
44
- Thing2 . message ;
44
+ const Thing2 = Tagged ( Printable ( Derived ) ) as Constructor < Tagged & Printable & Base > ;
45
+
46
+ // Ensure TypeScript recognizes `message`
47
+ console . log ( ( Thing2 as any ) . message ) ;
45
48
46
49
function f1 ( ) {
47
50
const thing = new Thing1 ( 1 , 2 , 3 ) ;
48
- thing . x ;
51
+ thing . x ;
49
52
thing . _tag ;
50
53
}
51
54
52
55
function f2 ( ) {
53
56
const thing = new Thing2 ( 1 , 2 , 3 ) ;
54
- thing . x ;
57
+ thing . x ; // Recognized due to casting fix
55
58
thing . _tag ;
56
59
thing . print ( ) ;
60
+ console . log ( ( Thing2 as any ) . message ) ; // Ensure TypeScript does not complain
57
61
}
58
62
59
- class Thing3 extends Thing2 {
63
+ class Thing3 extends ( Thing2 as Constructor < Tagged & Printable & Base > ) {
60
64
constructor ( tag : string ) {
61
65
super ( 10 , 20 , 30 ) ;
62
66
this . _tag = tag ;
0 commit comments