-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
I want to make use of inference when defining a class. Thus, I create a function returning a class instead of defining a class the normal way:
function Model<P extends Properties>(p: P) {
return class {
static create() {
create(): /*use of P somehow*/
}
}
}
class User extends Model({
a: { type: Type.String }
}) {};
let user: User = new User();
Though, I think the line class User extends Model() {};
is a bit non-idiomatic-js and ugly. It would be great if I could do this instead:
function defineModel<P extends Properties>(p: P) {
return class {
static create() {
create(): /*use of P somehow*/
}
}
}
const User = defineModel({
a: { type: Type.String }
});
let user: User = new User(); // I can use 'User' as a type here
At the end, this is working in JS, but TS prevents me.
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript