I have some classes which all have a property called data. I have a type definition for the data type mapping which I'd like to use in the generics definition. So this is my code:
type DataTypes = {
age: number;
firstName: string;
lastName: string;
};
abstract class AbstractBase<T extends DataTypes> {
data: T;
}
class AgeComponent extends AbstractBase<DataTypes.age> {}
class FirstNameComponent extends AbstractBase<DataTypes.firstName> {}
class LastNameComponent extends AbstractBase<DataTypes.lastName> {}
So when using abstract class AbstractBase<T extends DataTypes> I'd like to tell TypeScript to accept the types according to the mappings in the type DataTypes.
Is this possible with TypeScript?