I have been encountering challenges with generics in TypeScript for quite some time now. My current setup is as follows:
First, there is a generic class defined as:
class Entity {
public static schema = {};
}
Then, there is a class that extends the generic class:
class User extends Entity {
public static schema = {
username: ""
}
}
When I try to instantiate the class and use its parameters like this:
let user = new User();
user.username = "John Doe" //this does not work
I have experimented with using parameters and creating a generic type like:
type EntityType<T> = {
[k in keyof T]: T[k];
};
However, I have struggled to make it function properly. I attempted using index signatures with interfaces and types but encountered numerous syntax errors and could not find a way to resolve them.
Are there any suggestions on how I can achieve this or something similar?