wobsoriano / trpc-nuxt

End-to-end typesafe APIs in Nuxt applications.
trpc-nuxt.vercel.app
MIT License
687 stars 39 forks source link

Stop relying on internal types of trpc and nuxt #149

Closed AlexXanderGrib closed 10 months ago

AlexXanderGrib commented 10 months ago

Why?

Usage of internal types was a massive headache for me for last 4 hours. In some of my project typescript decides to respect "exports" field in package.json, and internal types become any. So data field in useQuery() also became any and i broke the prod.

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
trpc-nuxt ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 6, 2024 8:49am
AlexXanderGrib commented 10 months ago

Found cause of typescript behavior. It is broken by moduleResolution: "Bundler" set in tsconfig.json by nuxt. But it still better be fixed on your side. Quick fix for everybody with same issue:

// nuxt.config.ts
export default defineNuxtConfig({
  typescript: {
    strict: true,
    tsConfig: {
      compilerOptions: {
        moduleResolution: "Node"
      }
    }
  },
});