-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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();
}
}
appsforartists, aluanhaddad, dzolnjan, mmukarram, eps1lon and 8 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript