我相信所有的对象属性都是可选的,所以我没有完全理解错误。 因为我已经将属性设为可选,而不是对象本身?
错误
Expected 1 arguments, but got 0. TS2554
71 | // Get the claims on the initial page load
72 | useEffect(() => {
> 73 | fetchClaimDetails();
| ^
74 | }, []);
75 |
76 | return (
组件
interface fetchClaimDetailsQueryParams {
status?: string | null;
clientClaimId?: string | null;
}
const fetchClaimDetails = async ({
clientClaimId = null,
status = null
}: fetchClaimDetailsQueryParams) => {
......
useEffect(() => {
fetchClaimDetails();
}, []);
最佳答案
是的。使对象成为可选对象不会修复错误,因为对象正在参数列表中被解构。你需要这样的东西:
const fetchClaimDetails = async (paramsObj: fetchClaimDetailsQueryParams = {
clientClaimId: null,
status: null
}) => {
const {
clientClaimId,
status
} = paramsObject;
}
这应该使参数可选,同时提供有效的默认值。
关于javascript - 预期有 1 个参数,但得到 0 个参数。TS2554 - 可选对象属性但不是对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69042339/