Description
Follow up to talking to myself in #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 of tsconfig.app.json
. It seems the logic to pick them is different between Volar and tsserver, as changing their order in tsconfig.json
causes Volar to be the one to select tsconfig.vitest.json
instead of tsconfig.app.json
.
Adding the following to tsconfig.vitest.json
:
"references": [
{ "path": "./tsconfig.app.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:
- We are using
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:
diff --git a/.gitignore b/.gitignore
index 38adffa..b2e683b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@ dist
dist-ssr
coverage
*.local
+types
+*.tsbuildinfo
/cypress/videos/
/cypress/screenshots/
diff --git a/package.json b/package.json
index 4c8c275..1a7cbc7 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"test:e2e": "start-server-and-test preview http://localhost:4173/ 'cypress open --e2e'",
"test:e2e:ci": "start-server-and-test preview http://localhost:4173/ 'cypress run --e2e'",
"build-only": "vite build",
- "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
+ "type-check": "vue-tsc --build",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
},
"dependencies": {
diff --git a/tsconfig.app.json b/tsconfig.app.json
index cdbea1d..0e1bcdc 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -3,6 +3,8 @@
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
+ "emitDeclarationOnly": true,
+ "declarationDir": "types",
"composite": true,
"baseUrl": ".",
"paths": {
diff --git a/tsconfig.config.json b/tsconfig.config.json
index c2d3a30..8577b3c 100644
--- a/tsconfig.config.json
+++ b/tsconfig.config.json
@@ -2,6 +2,8 @@
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*"],
"compilerOptions": {
+ "emitDeclarationOnly": true,
+ "declarationDir": "types",
"composite": true,
"types": ["node"]
}
diff --git a/tsconfig.vitest.json b/tsconfig.vitest.json
index d080d61..d0d8b87 100644
--- a/tsconfig.vitest.json
+++ b/tsconfig.vitest.json
@@ -2,8 +2,13 @@
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
+ "emitDeclarationOnly": true,
+ "declarationDir": "types",
"composite": true,
- "lib": [],
+ "lib": ["ES2016"],
"types": ["node", "jsdom"]
- }
+ },
+ "references": [
+ { "path": "./tsconfig.app.json" }
+ ]
}