1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
=== tests/cases/conformance/classes/mixinClassesAnonymous.ts ===
type Constructor<T> = new(...args: any[]) => T;
>Constructor : Constructor<T>
>args : any[]
class Base {
>Base : Base
constructor(public x: number, public y: number) {}
>x : number
>y : number
}
class Derived extends Base {
>Derived : Derived
>Base : Base
constructor(x: number, y: number, public z: number) {
>x : number
>y : number
>z : number
super(x, y);
>super(x, y) : void
>super : typeof Base
>x : number
>y : number
}
}
const Printable = <T extends Constructor<Base>>(superClass: T) => class extends superClass {
>Printable : <T extends Constructor<Base>>(superClass: T) => { new (...args: any[]): (Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & T
><T extends Constructor<Base>>(superClass: T) => class extends superClass { static message = "hello"; print() { const output = this.x + "," + this.y; }} : <T extends Constructor<Base>>(superClass: T) => { new (...args: any[]): (Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & T
>superClass : T
>class extends superClass { static message = "hello"; print() { const output = this.x + "," + this.y; }} : { new (...args: any[]): (Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & T
>superClass : Base
static message = "hello";
>message : string
>"hello" : "hello"
print() {
>print : () => void
const output = this.x + "," + this.y;
>output : string
>this.x + "," + this.y : string
>this.x + "," : string
>this.x : number
>this : this
>x : number
>"," : ","
>this.y : number
>this : this
>y : number
}
}
function Tagged<T extends Constructor<{}>>(superClass: T) {
>Tagged : <T extends Constructor<{}>>(superClass: T) => { new (...args: any[]): C; prototype: Tagged<any>.C; } & T
>superClass : T
class C extends superClass {
>C : C
>superClass : {}
_tag: string;
>_tag : string
constructor(...args: any[]) {
>args : any[]
super(...args);
>super(...args) : void
>super : T
>...args : any
>args : any[]
this._tag = "hello";
>this._tag = "hello" : "hello"
>this._tag : string
>this : this
>_tag : string
>"hello" : "hello"
}
}
return C;
>C : { new (...args: any[]): C; prototype: Tagged<any>.C; } & T
}
const Thing1 = Tagged(Derived);
>Thing1 : { new (...args: any[]): Tagged<typeof Derived>.C; prototype: Tagged<any>.C; } & typeof Derived
>Tagged(Derived) : { new (...args: any[]): Tagged<typeof Derived>.C; prototype: Tagged<any>.C; } & typeof Derived
>Tagged : <T extends Constructor<{}>>(superClass: T) => { new (...args: any[]): C; prototype: Tagged<any>.C; } & T
>Derived : typeof Derived
const Thing2 = Tagged(Printable(Derived));
>Thing2 : { new (...args: any[]): Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C; prototype: Tagged<any>.C; } & { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>Tagged(Printable(Derived)) : { new (...args: any[]): Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C; prototype: Tagged<any>.C; } & { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>Tagged : <T extends Constructor<{}>>(superClass: T) => { new (...args: any[]): C; prototype: Tagged<any>.C; } & T
>Printable(Derived) : { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>Printable : <T extends Constructor<Base>>(superClass: T) => { new (...args: any[]): (Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & T
>Derived : typeof Derived
Thing2.message;
>Thing2.message : string
>Thing2 : { new (...args: any[]): Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C; prototype: Tagged<any>.C; } & { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>message : string
function f1() {
>f1 : () => void
const thing = new Thing1(1, 2, 3);
>thing : Tagged<typeof Derived>.C & Derived
>new Thing1(1, 2, 3) : Tagged<typeof Derived>.C & Derived
>Thing1 : { new (...args: any[]): Tagged<typeof Derived>.C; prototype: Tagged<any>.C; } & typeof Derived
>1 : 1
>2 : 2
>3 : 3
thing.x;
>thing.x : number
>thing : Tagged<typeof Derived>.C & Derived
>x : number
thing._tag;
>thing._tag : string
>thing : Tagged<typeof Derived>.C & Derived
>_tag : string
}
function f2() {
>f2 : () => void
const thing = new Thing2(1, 2, 3);
>thing : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
>new Thing2(1, 2, 3) : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
>Thing2 : { new (...args: any[]): Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C; prototype: Tagged<any>.C; } & { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>1 : 1
>2 : 2
>3 : 3
thing.x;
>thing.x : number
>thing : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
>x : number
thing._tag;
>thing._tag : string
>thing : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
>_tag : string
thing.print();
>thing.print() : void
>thing.print : () => void
>thing : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
>print : () => void
}
class Thing3 extends Thing2 {
>Thing3 : Thing3
>Thing2 : Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C & Printable<typeof Derived>.(Anonymous class) & Derived
constructor(tag: string) {
>tag : string
super(10, 20, 30);
>super(10, 20, 30) : void
>super : { new (...args: any[]): Tagged<{ new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived>.C; prototype: Tagged<any>.C; } & { new (...args: any[]): Printable<typeof Derived>.(Anonymous class); prototype: Printable<any>.(Anonymous class); message: string; } & typeof Derived
>10 : 10
>20 : 20
>30 : 30
this._tag = tag;
>this._tag = tag : string
>this._tag : string
>this : this
>_tag : string
>tag : string
}
test() {
>test : () => void
this.print();
>this.print() : void
>this.print : () => void
>this : this
>print : () => void
}
}
// Repro from #13805
const Timestamped = <CT extends Constructor<object>>(Base: CT) => {
>Timestamped : <CT extends Constructor<object>>(Base: CT) => { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & CT
><CT extends Constructor<object>>(Base: CT) => { return class extends Base { timestamp = new Date(); };} : <CT extends Constructor<object>>(Base: CT) => { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & CT
>Base : CT
return class extends Base {
>class extends Base { timestamp = new Date(); } : { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & CT
>Base : object
timestamp = new Date();
>timestamp : Date
>new Date() : Date
>Date : DateConstructor
};
}
|