Skip to content
Advertisement

how to type for object of object in typescript

How to type for following data. I have to type for progress object

const progress = {
   "1": {
      topic: [1,3,4],
      assessment: [1,2,4,],
   },
   "2": {
      topic: [1,3,4],
      assessment: [1,2,4,],
   },
   ....
}

Advertisement

Answer

There is built-in type – Record<K, V>

type Obj = Record<string, {topic: number[], assessment: number[]}>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement