-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vitest typecheck
does not work when TypeScript references
are used with noEmit
#3752
Comments
I have now created a better reproduction: https://github.com/scottwillmoore/vitest-with-typescript-references! |
@scottwillmoore Thanks for this issue. Recently I released TSTyche, a type testing tool for TypeScript, and was looking around for challenging cases. TSTyche handles Repo: https://github.com/tstyche/tstyche TSTyche has more to offer. Testing on specific version of TypeScriptSimply like this: Readable assertion errorsTSTyche's own assertions makes life easier. For example, if a matcher like PerformanceIn an empty repo with just one type test, TSTyche is slightly faster than Vitest. In a large monorepo TSTyche is 2x faster. (EDIT: TSTyche is 3-4x faster in another medium size repo, which is not a monorepo, but a single package and it has no How it worksTSTyche uses TypeScript's project service API, which allows retrieving type information per file. Instead of building the whole program, only minimal information needed to analyse particular file is collected. That is why it is faster, and can provide custom error messages, and can implement @sheremet-va We talked about type testing and interface Matchers<R, T = unknown> {
[key: string]: (expected: T) => R;
}
// @ts-expect-error: requires a type argument
type M = Matcher<>; Yep, those are two syntax errors. Compiling and executing the file does not catch them. Also the import { expect } from "tstyche";
interface Matchers<R, T = unknown> {
[key: string]: (expected: T) => R;
}
expect<Matchers>().type.toRaiseError("requires between 1 and 2 type arguments"); |
There was no strong reason for maintaining project references, especially because some of the tooling doesn't support it. By using a single config we make TypeScript checks faster and tools aren't running into problems. - TypeScript ESLint: typescript-eslint/typescript-eslint#2094 - eslint-import-resolver-typescript: typescript-eslint/typescript-eslint#2094 - Vitest: vitest-dev/vitest#3752 - Remix also didn't work, but I wasn't able to find the issue, probablt esbuild So that's at least 4 tools not working. 😄
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 atsconfig.node.json
, which are combined with the use of TypeScript references. This allows the web files and the configuration files to receive differentcompilerOptions
. In my projects I tend to create a minimaltsconfig.json
which referencestsconfig.node.json
andtsconfig.web.json
.The problem occurs when references are used with
noEmit
such as whenvitest
executestsc --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 at70387a6
, and runnpm run test:types
in thepackages/app
directory.I have now created a better reproduction: https://github.com/scottwillmoore/vitest-with-typescript-references!
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: