2

I'm defining the following function:

const Text = ({
  align = 'left',
  children,
  className,
  color = 'middleGrey',
  size = 'big',
  light = false,
}: Props) => ()

And as I'm using typescript, I have defined the following interface:

interface Props {
  align: string
  children: ReactNode
  className: string
  color: string
  size?: string
  light: boolean
}

But this makes me write 2 times every property.

Is there a better way to write this kind of code?

1 Answer 1

5

Unfortunately not. Destructuring syntax does not support specifying type annotations. There is an issue on this topic but it is open and not particularly active.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.