π Search Terms
class factory
Checked all opened issues and the 5 first pages of the closed ones. Also searched for existing issues with IA.
β
Viability Checklist
β Suggestion
Playground Link
Currently, if we have a class factory:
function classFactory<T extends Record<string, any>>(props: T) {
class Foo {
protected foo(){} // needs to disable declaration files.
}
return Foo as {new(): Foo&T};
}
And we assign the result into a constant variable:
const Klass = classFactory({a: 34})
Then, not only K can't be used as a type, but its type description is ugly:
const Klass: new () => classFactory<{
a: number;
}>.Foo & {
a: number;
}
Therefore, I'd like it to be equivalent to class Klass extends classFactory({a: 34}) {}, i.e. to produce a class Klass type.
π Motivating Example
The type description would be cleaner class Klass instead of:
const Klass: new () => classFactory<{
a: number;
}>.Foo & {
a: number;
}
Also, we will be able to use it as a type which could be quite useful. For exemple we would then be able to export default the generated class with its type.
π» Use Cases
Currently there are 2 workarounds:
1/ Using class Klass extends classFactory({foo: 34}) {}. However this creates an additional class and is more verbose to write.
2/ Re-creating the type. However dynamics and protected properties cause issues. This require to duplicate information, and likely require unsafe type casting of the factory function result.
π Search Terms
class factory
Checked all opened issues and the 5 first pages of the closed ones. Also searched for existing issues with IA.
β Viability Checklist
β Suggestion
Playground Link
Currently, if we have a class factory:
And we assign the result into a constant variable:
Then, not only
Kcan't be used as a type, but its type description is ugly:Therefore, I'd like it to be equivalent to
class Klass extends classFactory({a: 34}) {}, i.e. to produce aclass Klasstype.π Motivating Example
The type description would be cleaner
class Klassinstead of:Also, we will be able to use it as a type which could be quite useful. For exemple we would then be able to
export defaultthe generated class with its type.π» Use Cases
Currently there are 2 workarounds:
1/ Using
class Klass extends classFactory({foo: 34}) {}. However this creates an additional class and is more verbose to write.2/ Re-creating the type. However dynamics and
protectedproperties cause issues. This require to duplicate information, and likely require unsafe type casting of the factory function result.