NuxtN
Nuxt2y ago
3 replies
Gumaa

What is a standard way of handling typescript in Nuxt3

I'm starting a fresh project and I wonder what should I do about typescript in Nuxt 3.
Normally I would create a folder types and put my ordinary types there and import them in my components. But is that a "standard" approach in new Nuxt?

Since other stuff is auto imported maybe the expected way is to add this folder to auto imports?
// nuxt.config.ts:
imports: {
  dirs: ['types/*.ts', 'types/**/*.ts'],
},


Or maybe I should just declare types globally?

// types/whatever.d.ts

declare global {
  type MyType{
    ...
  }
}

export {};


Or stick to the old way?
For example Nuxtr does not even recommend any file structure for types, so maybe there is completely different way of handling it?
Was this page helpful?