Consider the following object:
class Product {
constructor(
public metadata: Metadata,
public topic: Topic,
public title = 'empty'
) {}
...
}
I am looking to define an interface:
interface State<T> {
}
This interface should ensure that a product: State<Product>
shares the same structure as the Product class, but all leaf-level properties are boolean. This means that the product
object should have a title property of type boolean.
I reviewed the readonly example on mapped types, but it seems that in this case I may need a composite approach:
interface State<T> {
[p in keyof T]: typeof T[p] === 'object' ? State<T[p]> : boolean;
}
Do you have any suggestions on how to implement this effectively?