【发布时间】:2023-03-07 00:44:01
【问题描述】:
我收到此错误:
D:/Downloads/Uber-Website-Clone-master/src/App.tsx D:/Downloads/Uber-Website-Clone-master/src/App.tsx(17,7) 中的 TypeScript 错误: 没有重载匹配此调用。 Overload 1 of 2, '(props: Readonly): LoadScript',给出了以下错误。
D:/Downloads/Uber-Website-Clone-master/src/App.tsx
TypeScript error in D:/Downloads/Uber-Website-Clone-master/src/App.tsx(17,7):
No overload matches this call.
Overload 1 of 2, '(props: Readonly<LoadScriptProps>): LoadScript', gave the following error.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Overload 2 of 2, '(props: LoadScriptProps, context?: any): LoadScript', gave the following error.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'. TS2769
15 | <div className="App">
16 | <LoadScript
> 17 | googleMapsApiKey={process.env.REACT_APP_GOOGLE_TOKEN}
| ^
18 | libraries={['places']}
19 | >
20 | <CoordinatesProvider>
代码如下:
import React, { useEffect } from 'react';
import { LoadScript } from '@react-google-maps/api';
import './global.css';
import CoordinatesProvider from './context/coordinates';
import Header from './components/Header';
import Map from './components/Map';
import Search from './components/Search';
function App() {
return (
<div className="App">
<LoadScript
googleMapsApiKey={process.env.REACT_APP_GOOGLE_TOKEN}
libraries={['places']}
>
<CoordinatesProvider>
<Header />
<Search />
<Map />
</CoordinatesProvider>
</LoadScript>
</div>
);
}
export default App;
【问题讨论】:
标签: reactjs typescript google-maps react-redux