How can I get type by object property from generic?
What I want to do is ▼
type A = {data:string, name: string};
interface B<T> {
data: T['data'] // error.. want to be expected as string
...
}
How can I get type by object property from generic?
What I want to do is ▼
type A = {data:string, name: string};
interface B<T> {
data: T['data'] // error.. want to be expected as string
...
}
TypeScript does not know that T should have a property data. A constraint would fix this.
type A = { data:string, name: string };
interface B<T extends { data: any }>{
data: T['data']
}