This applies regardless of whether or not I intersect it with some bogus type, or have a reasonable constraint. So none of the following works.
Returning a plain T
export type Constructor<T> = new (...args: any[]) => T
export interface Timestamp {
timestamp: Date;
}
// plain old T
export function Timestamp<T, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
return class extends Base {
timestamp = new Date();
}
}
Constructor of T with a bogus object type ({})
export type Constructor<T> = new (...args: any[]) => T
export interface Timestamp {
timestamp: Date;
}
// Constructor of T with a bogus object type
export function Timestamp<T, CT extends Constructor<T & {}>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
return class extends Base {
timestamp = new Date();
}
}
Constructor of T where T is constrained to {}
export type Constructor<T> = new (...args: any[]) => T
export interface Timestamp {
timestamp: Date;
}
export function Timestamp<T extends {}, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
return class extends Base {
timestamp = new Date();
}
}
Constructor of T where T is constrained to object (see also #13805)
export type Constructor<T> = new (...args: any[]) => T
export interface Timestamp {
timestamp: Date;
}
export function Timestamp<T extends object, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
return class extends Base {
timestamp = new Date();
}
}
This applies regardless of whether or not I intersect it with some bogus type, or have a reasonable constraint. So none of the following works.
Returning a plain
TConstructor of
Twith a bogus object type ({})Constructor of
TwhereTis constrained to{}Constructor of
TwhereTis constrained toobject(see also #13805)