Open
Description
Creating a project with typescript and vitest
Vue.js - The Progressive JavaScript Framework
√ Add TypeScript? ... Yes
√ Add Vitest for Unit Testing? ... Yes
making a mistake somewhere and then running type-check
script reports the errors twice:
This is due to the fact that "src" is included in both tsconfig.app.json
and tsconfig.vitest.json
. This was introduced with #274
Not sure how to fix this. It's nice to have a separate tsconfig for vitest, but not sure it's worth it if it double reports the errors because of it.
Activity
cexbrayat commentedon Feb 5, 2024
Hi @unshame , thanks for the report.
I noticed it, but did not really mind personally.
@sodatea do you have an idea on how we could do better for this?
sjihdazii commentedon Apr 22, 2024
@sodatea @unshame I have an idea what the cause may be. The
tsconfig.json
references thetsconfig.app.json
and thetsconfig.vitest.json
. The vue tsc build will run for both files. So if both tsconfig files include the file with the error; the error will be shown twice.The solution could be changing the type check script in the package.json to:
"type-check": "vue-tsc --build ./tsconfig.vitest.json --force",
unshame commentedon Apr 23, 2024
@sjihdazii yeah, but that defeats the purpose of having two configs. The .vitest.json config has additional globals defined which are only available in the .test files.
tsconfig/bases
vuejs/tsconfig#32codethief commentedon Jul 25, 2024
Hi there, I just stumbled over this, too.
Why does
tsconfig.vitest.json
need toinclude
the production code (code-under-test) in the first place? Isn't this exactly the point of project references – to allow a split between different parts of the code base that need to run with different TSC settings & type declarations (production code needs client-side types, test code needs node & jsdom types etc.)?In other words, how about changing
tsconfig.vitest.json
to something likeNote that this requires setting something like
in
tsconfig.app.json
and configuringoutDir
appropriately (e.g. setting it./node_modules/.tmp/app
or something). Compare my comment here.EDIT: I uploaded some example code here.
unshame commentedon Jul 28, 2024
I was under the impression that vue-tsc didn't work with noEmit: false
Edit: oh, yeah, that works, cool
Edit2: seems not to work when importing .vue files in tests - I get a weird
File X.vue.ts is not listed within the file list of project Y. Projects must list all files or use an 'include' pattern.
. I assume it's the.vue.ts
extension and the way vue-tsc handles vue files that's causing the issue.And I'm unable to include just the .vue files with
"include": ["./src/**/*.test.ts", "./src/**/*.vue"]
or"include": ["./src/**/*.test.ts", "./src/**/*.vue.ts"]
. Only"include": ["src"]
works.Edit3: this issue has been fixed in volar 2.0.26 vuejs/language-tools#3526 so looks like this solution works 🎉
codethief commentedon Jul 29, 2024
@unshame I'm having trouble following you but I'm glad you found a fix!
For everyone else, I uploaded an example project the other day where I had
tsconfig.vitest.json
reference
the production code instead ofinclude
ing it and things seemed to work fine.unshame commentedon Aug 1, 2024
@codethief I was updating the comment as I was trying to implement your suggestion, so it came out a bit incomprehensible. Your approach works with vue-tsc version 2 or later. That was my main point.
It also works for npm/pnpm workspaces as I found out - I've been able to utilize ts project references properly by putting the following in the package.json of each workspace:
I never realized I could just reference the compiled types while still referencing the uncompiled code. And this works in vscode & webstorm without needing to pre-compile anything.
This, with the vitest tsconfig optimization, has cut down typechecking times for my project significantly (to one minute from seven).
So huge thanks!
unshame commentedon Aug 1, 2024
@cexbrayat would you consider using the approach @codethief proposed for this repo? I have some free time, so I can submit a PR.
cexbrayat commentedon Aug 2, 2024
Sure, we would be glad to get a PR and see if that improves the situation! 👍
unshame commentedon Aug 4, 2024
@cexbrayat what's the reason for putting e2e tsconfigs in the e2e folder and not including them in the references of the main tsconfig? Is it because of this same issue by any chance?
13 remaining items