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

0

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

1

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:

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like