-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Manually Typed RuntimeConfig inside Layer causes TypeScript error in app using this layer. #22282
Description
Environment
App:
- Operating System: `Darwin`
- Node Version: `v18.16.0`
- Nuxt Version: `3.6.5`
- Nitro Version: `2.5.2`
- Package Manager: `npm@9.5.1`
- Builder: `vite`
- User Config: `extends`, `typescript`, `devtools`
- Runtime Modules: `-`
- Build Modules: `-`
Layer:
- Operating System: `Darwin`
- Node Version: `v18.16.0`
- Nuxt Version: `3.6.5`
- Nitro Version: `2.5.2`
- Package Manager: `npm@9.5.1`
- Builder: `vite`
- User Config: `typescript`
- Runtime Modules: `-`
- Build Modules: `-`
Reproduction
- clone repo https://github.com/DawidKopys/nuxt-layers
- Run
npm iin nuxt-layer directory - Run
npm iin app directory - Run
npx vue-tsc --noEmit/npm run dev/npx nuxi typecheckinside app directory. You should get below error:
../nuxt-layer/modules/testModule.ts:13:16 - error TS2664: Invalid module name in augmentation, module 'nuxt/schema' cannot be found.
13 declare module 'nuxt/schema' {
~~~~~~~~~~~~~
Found 1 error in ../nuxt-layer/modules/testModule.ts:13
Describe the bug
I am defining a module inside a layer. This module exposes its options to runtime (as per nuxt docs).
I want to type these runtime options manually so that I can have better DX inside other parts of the layer. For example - I would like to have both working typecheck and IntelliSense for the testModuleRuntimeConfig inside /nuxt-layer/components/HelloWorld.vue:
For the above reason, I am manually typing runtime config (again, as per nuxt docs) inside the module testModule.ts.
It seems to do what I want - I do get typecheck and IntelliSense inside my layer.
The problem is - it is also causing an error inside an app extending the layer:
It seems to be a bug for me. I have not figured out a way to get the types working both in the layer and the app extending my layer*.
* well, to be honest, for some reason it does seem to work if I add package.json in the root of my repo, configure it to be a monorepo, and run npm i from this root. But I don't think it is always a solution. I don't want to put my app and layer in a monorepo.
Additional context
No response
Logs
No response