Set global type on Nuxt3 project
NuxtHi, 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
javascript
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.