-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
I use TypeScript references in my Vite projects as recommended in their official templates. For example, the React with TypeScript template creates both a tsconfig.json
and a tsconfig.node.json
, which are combined with the use of TypeScript references. This allows the web files and the configuration files to receive different compilerOptions
. In my projects I tend to create a minimal tsconfig.json
which references tsconfig.node.json
and tsconfig.web.json
.
The problem occurs when references are used with noEmit
such as when vitest
executes tsc --noEmit ...
to test the types of the project. This doesn't check any files declared in the references. In addition, you appear to get this error: TS6305: Output file '.../index.d.ts' has not been built from source file '.../index.ts'
.
This is a documented, and known issue with the TypeScript compiler. It also doesn't look like it is going to be resolved...
To fix this, at the moment there are two solutions:
-
Don't use TypeScript references for important types that need to be checked. For example, instead of using a minimal
tsconfig.json
withtsconfig.node.json
andtsconfig.web.json
, I decided to merge mytsconfig.web.json
back into mytsconfig.json
. Although not ideal, I think this should cover most instances of this problem. -
Use
tsc --build
withoutnoEmit
. You should setup anoutDir
so it doesn't pollute your source files. In addition, it is wasteful to build the project when you already use Vite, or another bundler... This would require an update to Vitest in order to be able to usevitest typecheck
again.
Reproduction
I don't have time to create a perfect reproduction of the issue, but will work on it when I have some more free time. I thought I would create this issue to help others discover and understand this problem.
For now, you could use this project at 70387a6
, and run npm run test:types
in the packages/app
directory.
I have now created a better reproduction: https://github.com/scottwillmoore/vitest-with-typescript-references!
System Info
System:
OS: Linux 5.15 NixOS 23.05 (Stoat) 23.05 (Stoat)
CPU: (6) x64 Intel(R) Core(TM) i5-8600K CPU @ 3.60GHz
Memory: 4.63 GB / 7.73 GB
Container: Yes
Shell: 5.2.15 - /run/current-system/sw/bin/bash
Binaries:
Node: 18.16.1 - /nix/store/l43bdmxxlkrzwic3q24ik366qyqg3s1g-nodejs-18.16.1/bin/node
npm: 9.5.1 - /nix/store/l43bdmxxlkrzwic3q24ik366qyqg3s1g-nodejs-18.16.1/bin/npm
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.