1

I have a React 17 / Typescript 4.5 project. package.json looks like this:

...
"scripts": {
  "start": "react-scripts start",
  "build": "yarn run tsc --build"
}

My code has some Typescript errors that don't cause issues at runtime. When I run react-scripts start, the code builds and runs successfully in the browser, and React turns the errors into warnings that show up on initial page load. Conversely, when I run yarn run tsc --build, I can't compile the project due to the errors.

Yes, of course I should fix the errors, and I will. But while my code is rapidly evolving, solving certain tricky Typescript problems is premature. It may be useful to compile the code and temporarily ignore the errors.

I realize I can turn off specific errors in tsconfig.json, but I'd like to temporarily ignore all errors (at least, ones where Javascript can still be emitted).

Basically, what I want is a tsc flag that turns errors into warnings, but according to this related question, that doesn't exist. So how does react-scripts manage this? How can I compile my project in spite of the errors?

1 Answer 1

2

react-scripts uses a webpack plugin called ForkTsCheckerWebpackPlugin (see this line), which runs TypeScript type checking in a separate process and isn't actually used to transform your code from TypeScript to JavaScript before you run it. Instead, it looks like create-react-app uses @babel/preset-typescript (see this line), which doesn't perform any type checking but rather transpiles your code from TypeScript to JavaScript, so that's why your code is still able to run with TypeScript errors since Babel doesn't actually do any type checking with your code.

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.