1

I learn to use React with Typescript. In the manual I see it uses the --scripts-version parameter for create new application:

create-react-app my-app --scripts-version=react-scripts-ts

Also I see create-react-app has the --typescript option. So, I can write this:

create-react-app my-app --typescript

What is difference of these approaches of React-based application creating? Does it make sense to specify both of these parameters? I.e.

create-react-app my-app --typescript --scripts-version=react-scripts-ts

1 Answer 1

1

It doesn't make sense to use both:

create-react-app my-app --typescript --scripts-version=react-scripts-ts

react-scripts-ts was deprecated:

create-react-app now supports typescript natively - read the guide for adding typescript to existing projects.

As create-react-app documentation states,

To start a new Create React App project with TypeScript, you can run:

npx create-react-app my-app --typescript

# or

yarn create-react-app my-app --typescript

The difference is that react-scripts-ts uses TypeScript instead of Babel, while create-react-app uses Babel with TypeScript plugin. This leads to some limitations:

Does not support namespaces. Workaround: Move to using file exports, or migrate to using the module { } syntax instead.

Does not support const enums because those require type information to compile. Workaround: Remove the const, which makes it available at runtime.

Does not support export = and import =, because those cannot be compiled to ES.next. Workaround: Convert to using export default and export const, and import x, {y} from "z".

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.