React native flow error: Computed properties may only be primitive literal values

React native flow error: Computed properties may only be primitive literal values

我有流类型错误

这是我的错误:

不能使用 field [1] 作为计算 属性。计算属性可能只是原始文字值,但这个可能是字符串文字 amountFrom

这是我的代码:

    const handleChangeAmountInputs = (value, field) => {
        if (value.includes(',')) {
          setAmountFilter({
            ...amountFilter,
            [field]: value.split(',').join(''),
          });
        } else {
          setAmountFilter({...amountFilter, [field]: value});
        }
      };

and here is how i call the function

      <TextInput
        placeholder={'Enter amount'}
        returnKeyType="done"
        keyboardType="decimal-pad"
        onChangeText={(value) => {
        handleChangeAmountInputs(value, 'amountFrom');
        }}
       />

假设仅基于您提供的代码片段,flow 必须隐式输入您的 field arg 作为字符串文字而不是字符串。

如果您向字段添加类型注释,我认为应该可以修复它。

const handleChangeAmountInputs = (value, field: string) => {