victorgarciaesgi / nuxt-typed-router

🚦Provide autocompletion and typecheck to Nuxt router
https://nuxt-typed-router.vercel.app
MIT License
362 stars 12 forks source link

Auto import types #121

Closed wJoenn closed 1 year ago

wJoenn commented 1 year ago

Is there a way to add some types to auto imports ? I wanna use RoutePathSchema as a prop type for a Link component because it'd be very helpful to have a TS error if I type a path wrong or something instead of just having the prop being a string And I'm able to use it by importing it

<script setup lang="ts">
  import type { RoutePathSchema } form "@typed-router"

  defineProps<{
    to: RoutePathSchema
  }>()
</script>

But ideally I'd like to have this type auto imported instead of having to import it everywhere 🤔 Is there a way to do that ?

I tried adding .nuxt/typed-router to the list or imported dirs in nuxt config but that's not working

export default defineNuxtConfig({
  imports: {
    dirs: [
      ".nuxt/typed-router"
    ]
  }
}
victorgarciaesgi commented 1 year ago

Hi! Don't think that's possible globally :/

wJoenn commented 1 year ago

You mean it's not possible to declare types globally ? Nuxt does it a lot by doing

declare globally {
  ...
}

Wouldn't that suffise ?

victorgarciaesgi commented 1 year ago

No, I mean I would have to do it for every type manually, I can't make imports types global on the fly, and it will polute all the workspace. But maybe you can do it by having a custom .d.ts where you declare the type globally and importing it from typed router

wJoenn commented 1 year ago

Yeah that's what I started doing but I wondered if there wasn't a way. Thanks for the answers Victor ! Cheers