0

我有一个功能(反应钩子):

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 中是通用

如何解决?

4

1 回答 1

1

试试这个

handleLeavePage键入函数的输出,而不是声明参数的类型useHandles

于 2019-10-12T19:43:51.240 回答