Set global type on Nuxt3 project


2023-12-08 20:18 (KST)

Language :

Hi, I’m Lovefield.

Recently, I've been writing almost all projects in typescript. I think the existence of a type has a great merit, so I use it often. Nuxt3, which I mainly use, is also using typescript as a base. If you use a type, you may have to use the same type in multiple files. It's simpler than you think to use the type globally in Nuxt3.

nuxt.config.ts setting

export default defineNuxtConfig({
   imports: {
       dirs: ["types"],

Set the "types" folder to be imported automatically using the "imports" property. In fact, all settings have been completed with this setting. You can now simply create the "*.d.ts" file in the "types" folder and declare either interface or type. The "*.d.ts" file means that it is a file with only a declaration.


Web Front-End developer

하고싶은게 많고, 나만의 서비스를 만들고 싶은 변태스러운 개발자입니다.