Skip to content

Commit 2a103ee

Browse files
committed
tsconfig: Use "solution" tsconfig for more correct type checking
The change in 2aa6462 is resulting in a vite.config.js and vite.config.d.ts being generated which we don't want. The work-around. To fix this, lets do the "solution" tsconfig approach as used by the create-vue project. This results in things like the following, all of which aren't enforced currently: * tsc allows "process.cwd()" in vite.config.ts and sum.test.ts but not in any src files such as app.ts * tsc allows document.createElement() in src files such as app.ts and in sum.test.ts (because jsdom exists there) but not in vite.config.ts which is just pure node environment. * Can't import test files into src files * Allows using new features such as "".replaceAll() in vite.config.ts which should be allowed because we're using node 20. See: * vitejs/vite#15913 * https://github.com/vuejs/create-vue/blob/12bf2889b9ca981bcfed894a7c24fa9db5e7bad5/template/tsconfig/base/tsconfig.app.json * https://github.com/vuejs/create-vue/blob/12bf2889b9ca981bcfed894a7c24fa9db5e7bad5/template/tsconfig/base/tsconfig.node.json * https://github.com/vuejs/create-vue/blob/12bf2889b9ca981bcfed894a7c24fa9db5e7bad5/template/tsconfig/vitest/tsconfig.vitest.json
1 parent f455d31 commit 2a103ee

10 files changed

+79
-36
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
!resources/
66
!package.json
77
!tsconfig.json
8-
!tsconfig.node.json
8+
!tsconfig.*.json
99
!vite.config.ts

.eslintrc.cjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ module.exports = {
1111
],
1212
parser: "@typescript-eslint/parser",
1313
parserOptions: {
14-
project: ["./tsconfig.json", "./tsconfig.node.json"],
14+
project: [
15+
"./tsconfig.json",
16+
"./tsconfig.app.json",
17+
"./tsconfig.node.json",
18+
"./tsconfig.vitest.json",
19+
],
1520
tsconfigRootDir: __dirname,
1621
},
1722
plugins: ["import"],

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Homestead.yaml
1616
auth.json
1717
npm-debug.log
1818
yarn-error.log
19-
*.tsbuildinfo
2019
/.fleet
2120
/.idea
2221
/.vscode

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
!.eslintrc.cjs
77
!package.json
88
!tsconfig.json
9-
!tsconfig.node.json
9+
!tsconfig.*.json
1010
!vite.config.ts

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"format-check": "prettier . --check"
1212
},
1313
"devDependencies": {
14+
"@tsconfig/node20": "^20.1.2",
1415
"@types/jsdom": "^21.1.6",
1516
"@types/node": "^20.11.20",
1617
"@vitest/coverage-v8": "^1.2.2",

pnpm-lock.yaml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.app.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"include": ["resources/js"],
3+
"exclude": ["resources/js/**/__tests__/*"],
4+
"compilerOptions": {
5+
"composite": true,
6+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
7+
"target": "ESNext",
8+
"useDefineForClassFields": true,
9+
"module": "ESNext",
10+
// Set to empty to avoid accidental inclusion of unwanted types
11+
"types": [],
12+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
13+
"skipLibCheck": true,
14+
15+
/* Bundler mode */
16+
"moduleResolution": "bundler",
17+
"allowImportingTsExtensions": true,
18+
"resolveJsonModule": true,
19+
"isolatedModules": true,
20+
"noEmit": true,
21+
22+
/* Absolute imports */
23+
"paths": {
24+
"@/*": ["./resources/js/*"]
25+
},
26+
27+
/* Linting */
28+
"strict": true,
29+
"noUnusedLocals": true,
30+
"noUnusedParameters": true,
31+
"noFallthroughCasesInSwitch": true
32+
}
33+
}

tsconfig.json

+11-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
{
2-
"compilerOptions": {
3-
"target": "ESNext",
4-
"useDefineForClassFields": true,
5-
"module": "ESNext",
6-
"lib": ["ESNext", "DOM", "DOM.Iterable"],
7-
"skipLibCheck": true,
8-
9-
/* Bundler mode */
10-
"moduleResolution": "bundler",
11-
"allowImportingTsExtensions": true,
12-
"resolveJsonModule": true,
13-
"isolatedModules": true,
14-
"noEmit": true,
15-
16-
/* Absolute imports */
17-
"paths": {
18-
"@/*": ["./resources/js/*"]
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./tsconfig.app.json"
196
},
20-
21-
/* Linting */
22-
"strict": true,
23-
"noUnusedLocals": true,
24-
"noUnusedParameters": true,
25-
"noFallthroughCasesInSwitch": true
26-
},
27-
"include": ["resources/js"],
28-
"references": [{ "path": "./tsconfig.node.json" }]
7+
{
8+
"path": "./tsconfig.node.json"
9+
},
10+
{
11+
"path": "./tsconfig.vitest.json"
12+
}
13+
]
2914
}

tsconfig.node.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2+
"extends": "@tsconfig/node20/tsconfig.json",
3+
"include": ["vite.config.ts"],
24
"compilerOptions": {
35
"composite": true,
4-
"skipLibCheck": true,
6+
"noEmit": true,
7+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
8+
59
"module": "ESNext",
6-
"moduleResolution": "bundler",
7-
"allowSyntheticDefaultImports": true,
8-
"strict": true
9-
},
10-
"include": ["vite.config.ts"]
10+
"moduleResolution": "Bundler",
11+
"types": ["node"]
12+
}
1113
}

tsconfig.vitest.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.app.json",
3+
"exclude": [],
4+
"compilerOptions": {
5+
"composite": true,
6+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",
7+
8+
"types": ["node", "jsdom"],
9+
"lib": []
10+
}
11+
}

0 commit comments

Comments
 (0)