我的项目中有这样一个笑话
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
您需要显式指定函数的返回类型。 由于函数是async
,它返回一个promise
,围绕HotelService.GetByIdAsync(标识符)
返回的数据进行包装
const action = async (): Promise</*type of data wrapped in promise*/> => {
return await hotelService.getByIdAsync(Identifier);
};
action
函数未指定返回类型,因此出现错误。 为了消除linting错误,您需要将返回类型设置为promise
,因为该函数是异步的,因此只返回一个没有实际值的已解析的promise:
const action = async () : Promise<void> => {
await hotelService.getByIdAsync(Identifier);
};