How do I use the next-env.d.ts file in Next.js?

柔情痞子 提交于 2020-05-29 11:04:06

问题


I noticed a file called next-env.d.ts in my Next.js typescript project. I wanted to declare some enums that I can use throughout my Next.js files. How do I do this and then access these enums throughout my project?


回答1:


next-env.d.ts file is explained here: https://nextjs.org/docs/basic-features/typescript

A file named next-env.d.ts will be created in the root of your project. This file ensures Next.js types are picked up by the TypeScript compiler. You cannot remove it, however, you can edit it (but you don't need to).

For what your are trying to achieve with the enums, you can export your enum as a regular ES Module, so you can import it whenever you want in your code.

Hope that helps.



来源:https://stackoverflow.com/questions/61420392/how-do-i-use-the-next-env-d-ts-file-in-next-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!