Let's say we have that type:
type Product = {
id: string;
name: string;
isActive: boolean;
isAvailable: boolean;
}
Is it possible to dynamically create a new type from this one, but with keys as snake_case such as:
type ProductDb = {
id: string;
name: string;
is_active: boolean;
is_available: boolean;
}
If fact, I would like to define an Object <-> Database mapper that would be like:
class Mapper<Product, ProductDB> {
ObjectToDb = (object: Product): ProductDb => {};
DbToObject = (db: ProductDb): Product => {}
}
To go further it would be great to have a generic version of this mapper:
class Mapper<T, G> {
ObjectToDb = (object: T): G => {};
DbToObject = (db: G): T => {}
}