I just created a react typscript app with the create-react-app tool and i found a file with name react-app-env.d.ts in the project structure. I need to know what is the porpose of this file
The react-app-env. d. ts references the types of react-scripts , and helps with things like allowing for SVG imports.
Do not remove the react-app-env. d. ts file to avoid errors.
At the end of the day, the only difference between TypeScript and JavaScript React project is that its file extension ends with . tsx and the other ends with . js .
This file references TypeScript types declarations that are specific to projects started with Create React App.
These type declarations add support for importing resource files such as bmp, gif, jpeg, jpg, png, webp, and svg. That means that the following import will work as expected without errors:
import logo from './logo.svg';
It also adds support for importing CSS Modules. This relates to import of files with .module.css,.module.scss, and .module.sass extensions.
Checkout this blog post
Exactly as @mazedul-islam said
This file is only for ensuring that create-react-app essential types are picked up by the Typescript compiler. It's better to not remove or change since it might get updated by any possible changes in create-react-app. Next.js does the same thing and its explanation might provide better insight: https://nextjs.org/docs/basic-features/typescript#existing-projects
This file has a triple-slash directive which is just referring to a file with some types definitions. You can inspect it or open it directly from the node_module: node_modules/react-scripts/lib/react-app.d.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With