Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the react-app-env.d.ts in a react typescript project for

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

like image 478
Houssem TRABELSI Avatar asked Apr 26 '21 08:04

Houssem TRABELSI


People also ask

What is React-app-ENV D TS do?

The react-app-env. d. ts references the types of react-scripts , and helps with things like allowing for SVG imports.

Can I remove React-app-ENV D TS?

Do not remove the react-app-env. d. ts file to avoid errors.

What is the difference between React and TypeScript?

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 .


2 Answers

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

like image 81
Mazedul Islam Avatar answered Oct 19 '22 08:10

Mazedul Islam


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

like image 2
Max Medina Avatar answered Oct 19 '22 09:10

Max Medina