My attempt at utilizing Omit<T, 'id'>
within a generic function is shown below:
class Model{
static create<T extends Model>(a: Omit<T, 'id'>): number{
return 0;
}
id = 0;
title = 'test';
}
class Child extends Model{
child = true;
}
function createModel<T extends typeof Model>(model: T, data: Parameters<T['create']>[0]) : InstanceType<T> {
return {} as InstanceType<T>;
}
const instance = createModel(Child, {title: 'test', child :true }); // trying to include child properties here as the second argument
When using
Parameters<T.func<InstanceType<T>>>
, I encountered this error:
Cannot access 'T.func' because 'T' is a type, not a namespace. Did you mean to retrieve the type of the property 'func' in 'T' with 'T["func"]'?(2713)
Using
Parameters<T['create']<InstanceType<T>>>
resulted in:
Parameter 'InstanceType' implicitly has an 'any' type.
In addition, there was invalid syntax when createModel
had more than 6 parameters
Is there a way to reuse the parameter without introducing a common external type?