0
votes

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 ?

1

1 Answers

2
votes

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