【问题标题】:How to solve refers to a value, but is being used as a type here. Did you mean 'typeof DatePicker'?如何解决是指一个值,但在这里被用作一个类型。你的意思是'typeof DatePicker'吗?
【发布时间】: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 } />;
};

import components

function

你能解释一下如何解决这个问题以及我做错了什么吗?

【问题讨论】:

标签: reactjs typescript antd


【解决方案1】:

您应该将文件命名为 .tsx 而不是 .ts,因为其中包含 JSX...

【讨论】:

    猜你喜欢
    • 2021-08-02
    • 2021-07-07
    • 1970-01-01
    • 2020-12-22
    • 2020-11-01
    • 1970-01-01
    • 2021-07-12
    • 2020-03-23
    • 2019-08-29
    相关资源
    最近更新 更多