vendredi 27 mai 2022

a Type which statisfy Object that unlimited random keyName with different value format

I need a Type which statisfy Object that has a firstName proptery , value format is string, has a lastName proptery , value format is string, other random keyName ,value format is string[ ],

const personA = {
 firstName:"Bob" //alwways exist, 
 lastName:"Tom", //alwways exist
 hobbies:["cooking","singing","dancing"] //not always exist in an object instant
 ableToSpeak:["english","japaneses"]
//...other random keyName with value of string[]
}

const personB = {
 firstName:"Jim"
 lastName:"kATE",
 food:["cake","apple","rice"]
 //...other random keyName  with value of string[]
}

The following is not working, firstName and [keyName] are conflict

type HumanType {
  [keyName: string]: string[],
  firstName:string
  lastName:string
}

Property 'firstName' of type 'string' is not assignable to 'string' index type 'string[]'.




Aucun commentaire:

Enregistrer un commentaire