简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM