1

I use ReactJs with TypeScript and AntDesign and i have problem.

I've got the function which return AntDesignComponent, but typeScript throw error.

'TextArea' refers to a value, but is being used as a type here. Did you mean 'typeof TextArea'?ts(2749)

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)

Conversion of type 'string' to type 'Input' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' 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

Can u explain how to solve this problem and whats wrong i do ?

John Johnson
  • 61
  • 1
  • 7
  • Does this answer your question? ["Navbar refers to a value, but is being used as a type here" when trying to render a shallow copy of my component when testing](https://stackoverflow.com/questions/58341545/navbar-refers-to-a-value-but-is-being-used-as-a-type-here-when-trying-to-rend) – Michael Freidgeim Aug 05 '21 at 14:07

1 Answers1

6

You should name your file .tsx and not .ts because you have JSX in it…

Stéphane Veyret
  • 1,791
  • 1
  • 8
  • 15