慕婉清6462132
2022-10-13 19:42:32
我的項目中有這個笑話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
2 回答

阿晨1998
TA貢獻2037條經(jīng)驗 獲得超6個贊
您需要明確指定函數(shù)的返回類型。作為函數(shù)async,它返回一個Promise包裹在由返回的數(shù)據(jù)周圍的hotelService.getByIdAsync(Identifier)
const action = async (): Promise</*type of data wrapped in promise*/> => {
return await hotelService.getByIdAsync(Identifier);
};

泛舟湖上清波郎朗
TA貢獻1818條經(jīng)驗 獲得超3個贊
該action函數(shù)未指定返回類型,因此出現(xiàn)錯誤。為了擺脫掉毛錯誤,您需要將返回類型設(shè)置Promise<void>為函數(shù)是異步的,因此只返回一個沒有實際值的已解決承諾:
const action = async () : Promise<void> => {
await hotelService.getByIdAsync(Identifier);
};
添加回答
舉報
0/150
提交
取消