Home > Mobile >  Access a property of interface inside interface [Typescript]
Access a property of interface inside interface [Typescript]

Time:05-09

I'm trying to make a react component that accepts a data and dataKey prop. But I want to make sure dataKey exists as a key in data (along other properties in data). something like this

interface Props<T> {
  dataKey: string;
  data: { [dataKey]: string } & T; //This is not acceptable.
}

How can I accomplish this?

CodePudding user response:

Maybe you need something like this :

 interface Props<T> {
   dataKey: string;
   data: DataKey; 
 } 
        
  interface DataKey {
    dataKey: string;
    data: T; 
  }

CodePudding user response:

It seems like material-ui's OverridableComponent.

  • Related