Open segevfiner opened 2 years ago
For the tsconfig selection, there's an issue in TypeScript repo tracking that: https://github.com/microsoft/TypeScript/issues/48058
As of now, the vue-tsc
behavior is deterministic, and opposite to the tsc
behavior.
We chose to follow its behavior as it's a Vue project after all.
I'm still not sure what's the best way to type-check the source files when vitest
is present.
Will think more about that later.
2.
tsconfig.vitest.json
has"lib": []
, but this should probably be"lib": ["ES2016"]
to matchtsconfig.app.json
just without DOM.
This looks like a bug to me, needs to be fixed.
@sodatea Do try my proposed changes, especially in some existing project, let me know if it seems to work better or not. (Not sure if there is a conventional name for the directory used for declarationDir
for this configuration)
Let me know if you want me to send a PR with any of those changes.
I don't have the time to try it out now. @xiaoxiangmoe could you help take a look?
Argh. Just hit this again with it picking up tsconfig.vitest.json
giving me an error about stuff that comes from DOM.Iterable
not being defined.
@segevfiner Can you provide me a minimal reproduce demo to show the difference?
Try: https://github.com/segevfiner/create-vue-159. It errors in main.ts
and when running type-check
but is OK in VS Code when opening App.vue
as there is uses tsconfig.app.json
. While during type check and viewing ts files it is using tsconfig.vitest.json
.
I added your proposed changes to a semi-large project which includes Vitest, Cypress & Storybook. My painpoints:
tsconfig.*.json
file that extends tsconfig.app.json
will also cause the script to parse the app files. At best that means type-check
takes longer to run than needed, at worst it means errors pop up because the compilerOptions
are different.type-check
twice results in a false positive. There are multiple errors on the first time it runs. Once the files are generated though, any subsequent run of type-check
will pass without reporting the errors.Because the project is using Vitest, Cypress & Storybook it would be a blessing to get a good solution for this. I might look into this some more, but I'm probably unlikely to succeed.
Yeah. It's likely not perfect. I wish TS itself would have better handling for this... But the current situation is actively giving me false errors or allowing to use node where I should not, so we should find at least a solution to that...
tsconfig.vitest.json
has"lib": []
, but this should probably be"lib": ["ES2016"]
to matchtsconfig.app.json
just without DOM.
I just checked that @types/node
has already referenced the corresponding ES lib, e.g. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8d5e1a106b1b18250623e09a2a8469dc7ee52bca/types/node/index.d.ts#L73
So "lib": ["ES2016"]
would be redundant.
Try: https://github.com/segevfiner/create-vue-159. It errors in
main.ts
and when runningtype-check
but is OK in VS Code when openingApp.vue
as there is usestsconfig.app.json
. While during type check and viewing ts files it is usingtsconfig.vitest.json
.
It's a bug in @types/jsdom
. I've submitted a PR: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62769
Nevertheless, the type-checking experience could be better. I'll look further into it in the coming days.
TypeScript 5.0 now supports noEmit
in with project references/composite projects! Allowing us to switch to just vue-tsc --build
by adding noEmit
to the tsconfig.*.json
files!
But it also deprecates importsNotUsedAsValues
& preserveValueImports
in favor of verbatimModuleSyntax
which needs to be modified in @vue/tsconfig
, and support added to vue-tsc
, as it seems to currently break with this option https://github.com/vuejs/language-tools/issues/2343#issuecomment-1478541728 and there seems to be other breakages as well as adding "ignoreDeprecations": "5.0"
also gives other errors.
I've tried to wrap my head around these parts for the docs on this that I've written, but I've lost the current status. The project is now using --build
so I'm not sure what applies anymore. If anyone here has a good understanding of the overlap of these two files, could you please help me finish https://github.com/vuejs/create-vue/issues/265#issuecomment-2165816042 ?
In reference to tsconfig.vitest.json, it seems that including "lib": [],
overrides the lib entry from tsconfig.app.json. For example if you include "lib": ["esnext", "dom"],
in tsconfig.app.json, it doesn't have any effect, unless you remove "lib": [],
from tsconfig.vitest.json.
Follow up to talking to myself in https://github.com/vuejs/create-vue/pull/151 😛
Create a new create-vue project with everything but tsx selected. In this configuration, VS Code's builtin tsserver/TypeScript support seems to pick
tsconfig.vitest.json
, instead oftsconfig.app.json
. It seems the logic to pick them is different between Volar and tsserver, as changing their order intsconfig.json
causes Volar to be the one to selecttsconfig.vitest.json
instead oftsconfig.app.json
.Adding the following to
tsconfig.vitest.json
:Seems to make VS Code select
tsconfig.app.json
for ts files properly, but this is some pure guess work and I'm not sure where or how the logic to select an appropriate tsconfig works.In addition:
vue-tsc --noEmit -p tsconfig.vitest.json --composite false
to type check, but in case the user wants to add additional projects to the project references config, this won't type check them. Apparently--build
,composite
, and project references don't supportnoEmit
, so we need to useemitDeclarationOnly
,declarationDir
instead to make it emit types to some folder solely for the purpose of type checking. On the plus side, in this mode it reuses them when it can for faster type checking (It also enablesincremental
).tsconfig.vitest.json
has"lib": []
, but this should probably be"lib": ["ES2016"]
to matchtsconfig.app.json
just without DOM.So basically the following changes to the generated project seems to fix those things for me:
@sodatea