cli icon indicating copy to clipboard operation
cli copied to clipboard

Run typecheck for client *and* server with `nuxi typecheck`

Open TheAlexLichter opened this issue 2 years ago • 4 comments

When running nuxi typecheck, only the client types are checked right now. Ideally, also the tsconfig.json of the server should be used and the nitro/server side should be checked!

TheAlexLichter avatar Jan 06 '24 21:01 TheAlexLichter

Any status on this?

kaaax0815 avatar Jan 17 '25 09:01 kaaax0815

Hmm, maybe I'm testing incorrectly but the command seems to also typecheck server files in a local test project, can someone provide a minimal reproduction shows the lack of type checking on the nitro/server side? I'll use it to try and implement type checking if it is still lacking 🙏

BobbieGoede avatar Jan 17 '25 18:01 BobbieGoede

I made one here for my use case https://stackblitz.com/edit/server-typecheck-repro?file=nuxt.config.ts

I have to add the alias to the generated tsconfig.json for aliases to work. even tho it should be enough if its in the tsconfig.server.json

kaaax0815 avatar Jan 19 '25 14:01 kaaax0815

@kaaax0815 Thank you for the reproduction!

It actually looks like typecheck only checks client files (does not use tsconfig.server.json) which means the server directory should be excluded, the errors in your reproduction shouldn't be thrown at all.

The server files are not being excluded as expected due to explicit imports/references by included files, which in this case are the auto import types generated by nitro (nuxt.d.ts > types/nitro.d.ts > types/nitro-imports.d.ts).

@danielroe Should the nitro.d.ts types be included in the generated tsconfig.json or should these actually only be included in tsconfig.server.json?

The typecheck command ~~needs~~ may need to be changed to run two type checks, for client files and for server files, I can look into this, but we have to prevent the server files from being included in the client tsconfig.json (not sure how).

I have updated the reproduction and removed the additional alias config, running pnpm typecheck demonstrates server files are checked while tsconfig.server.json is not being used since it throws errors.

Related

  • https://github.com/nuxt/nuxt/issues/24087
  • https://github.com/nuxt/nuxt/issues/29263

BobbieGoede avatar Jan 19 '25 15:01 BobbieGoede