Jest / eslint中的函数缺少返回类型

我的项目中有这个笑话


const action = async () => {

                await hotelService.getByIdAsync(Identifier);

};


await expect(action()).rejects.toThrowError(FunctionalError);

但我有这个 eslint 错误


 92:28  error  Missing return type on function  @typescript-eslint/explicit-function-return-type


慕婉清6462132
浏览 113回答 2
2回答

阿晨1998

您需要明确指定函数的返回类型。作为函数async,它返回一个Promise包裹在由返回的数据周围的hotelService.getByIdAsync(Identifier)const action = async (): Promise</*type of data wrapped in promise*/> => {&nbsp; &nbsp;return await hotelService.getByIdAsync(Identifier);};

泛舟湖上清波郎朗

该action函数未指定返回类型,因此出现错误。为了摆脱掉毛错误,您需要将返回类型设置Promise<void>为函数是异步的,因此只返回一个没有实际值的已解决承诺:const action = async () : Promise<void> => {&nbsp; &nbsp; await hotelService.getByIdAsync(Identifier);};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript