0

const libraries = ['drawing', 'places', 'geometry'];
const {isLoaded, loadError } = useLoadScript({ googleMapsApiKey: '', libraries: libraries })

Mostafa Yasser
  • 145
  • 1
  • 2
  • 7
  • I've tried many solutions, the first was to make libraries as a constant value out of the parent function, but typescript keeps showing the same error which is: Type 'string[]' is not assignable to type '("drawing" | "places" | "geometry" | "localContext" | "visualization")[]'. – Mostafa Yasser Jun 08 '22 at 13:44
  • the second solution was using React.useRef() to make a reference to the libraries value, but that also shows the same error. – Mostafa Yasser Jun 08 '22 at 13:47

1 Answers1

0

You need a narrower type than string because the type of libraries is narrower. It's a union of specific strings.

Try const libraries: Array<"drawing" | "places" | "geometry"> = ['drawing', 'places', 'geometry'].