2

I have typescript code that I want to convert to Javascript:

interface Props {
  children?: ReactElement | Array<ReactElement>;
}

const Trail: React.FC<Props> = ({ children, ...props }) => {

How do i convert this to something similar in javascript since theres no interfaces?

2
  • 1
    Can you explain your use case exactly? TypeScript compiles to JavaScript; if you want to convert TypeScript to JavaScript, just compile it. This will remove interfaces and any other trace of the static type system. It that's not what you want, then you should elaborate what you expect to see that's different. Commented Mar 14, 2021 at 4:22
  • You just delete the whole interface and the type annotation : React.FC<Props>. You can still destructure your props in the same way, but you lose all of the information about their types because that only exists in typescript. Commented Mar 14, 2021 at 5:04

1 Answer 1

2

You remove it:

const Trail = ({ children, ...props }) => {

Just look at what Typescript generates.

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.