【发布时间】:2018-10-23 23:01:23
【问题描述】:
我的打字稿表现得很奇怪,需要帮助来解决它。
我正在尝试将 redux-form(v7) 与 reactstrap
Form.tsx
<Field
type="text"
component={InputField}
/>
<Field
type="password"
component={InputField}
/>
输入框
import {Input} from 'reactstrap';
import {WrappedFieldProps} from 'redux-form/lib/Field';
type Props = {
type?: string;
}
const InputField = (props: WrappedFieldProps & Props) => {
const { type, input } = props;
return(
<Input
type={type}
{...input}
/>
);
};
在这种情况下,我收到了 Typescript 错误:TS2322
Types of property 'type' are incompatible.
Type 'string | undefined' is not assignable to type '"number" | "select" | "textarea" | "text" | "hidden" | "color" | "email" | "file" | "radio" | "ch...'.
Type 'string' is not assignable to type '"number" | "select" | "textarea" | "text" | "hidden" | "color" | "email" | "file" | "radio" | "ch...'.
但如果我将 type?: string 更改为 type?: InputType; ( 类型 from reactstrap import {InputType} from 'reactstrap/lib/Input'; ) 那么它会解决 InputField 中的问题但后来我在 Form.tsx
【问题讨论】:
标签: reactjs typescript redux-form react-redux-form reactstrap