Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么会发生过载错误,即使一切正常?_Reactjs_Typescript - Fatal编程技术网

Reactjs 为什么会发生过载错误,即使一切正常?

Reactjs 为什么会发生过载错误,即使一切正常?,reactjs,typescript,Reactjs,Typescript,我正在使用TS开发我的第一个应用程序,当我尝试在react select元素中实例化一个道具时,出现以下错误: 未能编译 C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/src/Orders/OrderLocation.tsx TypeScript error in C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/sr

我正在使用TS开发我的第一个应用程序,当我尝试在react select元素中实例化一个道具时,出现以下错误:

未能编译

C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/src/Orders/OrderLocation.tsx
TypeScript error in C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/src/Orders/OrderLocation.tsx(66,13):

No overload matches this call.
  Overload 1 of 2, '(props: Props<Place, false, GroupTypeBase<Place>> | Readonly<Props<Place, false, GroupTypeBase<Place>>>): Async<...>', gave the following error.
    Type '(inputValue: string, callback: (places: Place[]) => void) => Promise<void>' is not assignable to type '(inputValue: string, callback: (options: readonly (Place | GroupTypeBase<Place>)[]) => void) => void | Promise<readonly (Place | GroupTypeBase<Place>)[]>'.
      Type 'Promise<void>' is not assignable to type 'void | Promise<readonly (Place | GroupTypeBase<Place>)[]>'.
        Type 'Promise<void>' is not assignable to type 'Promise<readonly (Place | GroupTypeBase<Place>)[]>'.
          Type 'void' is not assignable to type 'readonly (Place | GroupTypeBase<Place>)[]'.
  Overload 2 of 2, '(props: Props<Place, false, GroupTypeBase<Place>>, context: any): Async<Place, false, GroupTypeBase<Place>>', gave the following error.
    Type '(inputValue: string, callback: (places: Place[]) => void) => Promise<void>' is not assignable to type '(inputValue: string, callback: (options: readonly (Place | GroupTypeBase<Place>)[]) => void) => void | Promise<readonly (Place | GroupTypeBase<Place>)[]>'.  TS2769

    64 |             placeholder="Digite um endereço para entregar o pedido"
    65 |             className="filter"
  > 66 |             loadOptions={loadOptions}
       |             ^
    67 |             onChange={value => handleChangeSelect(value as Place)}
    68 |           />
    69 |         </div>
C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/src/Orders/OrderLocation.tsx
C:/Users/Lucas/OneDrive/Desktop/projetos/ws-sds2/dsdeliver/front-web/src/Orders/OrderLocation.tsx中的类型脚本错误(66,13):
没有与此调用匹配的重载。
重载2中的第1个,'(props:props | Readonly):Async'给出了以下错误。
Type'(inputValue:string,callback:(places:Place[])=>void)=>Promise'不可分配给Type'(inputValue:string,callback:(选项:只读(Place | GroupTypeBase)[])=>void=>void | Promise'。
类型“Promise”不可分配给类型“void | Promise”。
类型“Promise”不可分配给类型“Promise”。
类型“void”不可分配给类型“readonly(Place | GroupTypeBase)[]”。
重载2/2'(props:props,context:any):Async'给出了以下错误。
Type'(inputValue:string,callback:(places:Place[])=>void)=>Promise'不可分配给Type'(inputValue:string,callback:(选项:只读(Place | GroupTypeBase)[])=>void=>void | Promise'。TS2769
64 | placeholder=“Digite um endereço para entregar o pedido”
65 | className=“过滤器”
>66 | loadOptions={loadOptions}
|             ^
67 | onChange={value=>handleChangeSelect(值作为位置)}
68 |           />
69 |         
我在哪里分配这个道具

function OrderLocation({ onChangeLocation }: Props) {
  const [address, setAddress] = useState<Place>({
    position: initialPosition
  });

  const loadOptions = async (inputValue: string, callback: (places: Place[]) => void) => {
    const response = await fetchLocalMapBox(inputValue);

    const places = response.data.features.map((item: any) => {
      return ({
        label: item.place_name,
        value: item.place_name,
        position: {
          lat: item.center[1],
          lng: item.center[0]
        }
      });
    });


<AsyncSelect
            placeholder="Digite um endereço para entregar o pedido"
            className="filter"
            loadOptions={loadOptions}
            onChange={value => handleChangeSelect(value as Place)}
          />
函数OrderLocation({onChangeLocation}:Props){
常量[地址,设置地址]=使用状态({
位置:初始位置
});
const loadOptions=async(inputValue:string,callback:(places:Place[])=>void)=>{
const response=await fetchLocalMapBox(inputValue);
const places=response.data.features.map((项目:any)=>{
返回({
标签:item.place\u名称,
值:item.place\u名称,
职位:{
横向:项目中心[1],
液化天然气:项目中心[0]
}
});
});
handleChangeSelect(值作为位置)}
/>

loadOptions
无法返回承诺,因此我们需要删除
async
关键字,如下更改代码:


const loadOptions=(inputValue:string,callback:(places:Place[])=>void=>{
const handleAsync=async()=>{
const response=await fetchLocalMapBox(inputValue);
const places=response.data.features.map((项目:any)=>{
返回({
标签:item.place\u名称,
值:item.place\u名称,
职位:{
横向:项目中心[1],
液化天然气:项目中心[0]
}
});
}
handleAsync()
};

如果你有错误,请粘贴这些错误。不要使用链接到图片。请考虑修改这个问题中的代码,以便构成一个,当它落入独立IDE中时,清楚地显示你所面临的问题。这将允许那些想帮助你立即着手解决问题的人。ut首先需要重新创建它。它将使您得到的任何答案都可以根据定义良好的用例进行测试。查看此组件的类型定义(OrderLocation)以及您将
loadOptions
变量分配给的对象也会很有帮助。