【发布时间】:2021-01-12 10:38:33
【问题描述】:
我将 ReactJs 与 TypeScript 和 AntDesign 一起使用,但我遇到了问题。
我有返回 AntDesignComponent 的函数,但是 typeScript 抛出错误。
'TextArea' 指的是一个值,但在这里被用作一个类型。你是说'typeof TextArea'吗?ts(2749)
算术运算的左侧必须是“any”、“number”、“bigint”类型或枚举类型。ts(2362)
算术运算的左侧必须是“any”、“number”、“bigint”类型或枚举类型。ts(2362)
将“字符串”类型转换为“输入”类型可能是错误的,因为这两种类型都没有充分重叠。如果这是故意的,请将表达式转换为“未知”first.ts(2352)
export const getTypeFormElem = ({
type = 'input',
typeValue = 'text',
...props
}) => {
if (type === 'textarea') return <TextArea value='123' { ...props } />;
if (type === 'checkbox') return <Checkbox { ...props } />;
if (type === 'date') return <DatePicker { ...props } />;
return <Input type={ typeValue } {...props } />;
};
你能解释一下如何解决这个问题以及我做错了什么吗?
【问题讨论】:
标签: reactjs typescript antd