#Object and Array Props

10 messages · Page 1 of 1 (latest)

tepid sorrel
#

For props that are an object or array, is there a way that I can define the types of the keys used?

#
export interface Props {
  image: object
  caption?: string
  video?: string
}```
#

^ Take this example where I have an image object but would like to define that it has src and alt keys that are both strings.

shell cobalt
tepid sorrel
#

Thank you!

#

I can do something similar with arrays but wrap the image object in array brackets?

shell cobalt
#

Like an array of image objects?

tepid sorrel
#

Yeah.

#

What would I need to do if that were images for example.

shell cobalt
#

You can do {src:string, alt:string}[] or Array<{src:string, alt:string}>