我有一个功能(反应钩子):
function useHandles<TPreparedValues, TValues>({
onReject,
makeData,
}: ArgsType<TPreparedValues, TValues>) {
const handleLeavePage = (formData: TValues) => onReject(makeData(formData))
return {
handleLeavePage
}
}
其中 ArgsType 是:
type ArgsType<TPreparedValues, TValues> = {
onReject: (TPreparedValues) => Promise<void>,
makeData: TValues => TPreparedValues
};
然后我使用这个钩子:
const {
handleLeavePage,
} = useDocumentHandles<DocumentEditInputType, ValuesType>({
onReject,
makeData,
})
如您所见,我定义了TValues = ValuesType。当然,flowjs 应该从onReject类型中猜出来。
但是当我使用handleLeavePage时,我得到一个错误:
TValues
[1] is incompatible with ValuesType
[2] in the first argument of property onLeavePage
。
我认为 flowjs 不明白 TValue 在 handleLeavePage 中是通用的。
如何解决?