Using `vitest/importMeta` leaks Node types to web applications
Describe the bug
Projects for web applications need to be careful not to include Node types that could overshadow web browser APIs. For example setTimeout in browser types returns number while in Node it returns Timeout which causes errors like:
error TS2322: Type 'Timeout' is not assignable to type 'number'.
I was able to use Vitest to test my web library, because *.test.ts files were excluded from my tsconfig.json, but I am not able to use import.meta.vitest for inline tests as vitest/importMeta causes the Node types to be added to my project.
Below is link to minimal reproduction, but here's also a screenshot:
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-joykgq?file=src%2Fbasic.ts&view=editor
System Info
System:
OS: macOS 14.4.1
CPU: (12) arm64 Apple M2 Pro
Memory: 1.02 GB / 32.00 GB
Shell: 3.7.0 - /opt/homebrew/bin/fish
Binaries:
Node: 21.6.2 - /opt/homebrew/bin/node
npm: 10.2.4 - /opt/homebrew/bin/npm
Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 123.0.6312.105
Safari: 17.4.1
Safari Technology Preview: 17.4
npmPackages:
vite: latest => 5.2.7
vitest: latest => 1.4.0
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Some type declarations are importing types from vite. There's /// <reference types="node" /> in vite/dist/node/index.d.ts.
Some type declarations are importing types from
vite. There's/// <reference types="node" />invite/dist/node/index.d.ts.
Yep, and there should be no import of vite in importMeta or vitest