The objective is to run the type-checking command from the root of the project, which should validate the code across all packages specified in the workspaces
. The current setup successfully executes the tsc
command, but it does not report any type errors, despite the presence of issues in the code.
Here’s the output from the type-checking command:
$ bun --filter '*' typecheck
package-1 typecheck $ tsc
└─ Done in 80 ms
package-2 typecheck $ tsc
└─ Done in 79 ms
Root package.json
:
{
"name": "ts-monorepo",
"private": true,
"scripts": {
"typecheck": "bun --filter '*' typecheck"
},
"devDependencies": {
"typescript": "^5.8.3"
},
"workspaces": [
"package-1",
"package-2"
]
}
Root tsconfig.json
:
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"composite": true,
"erasableSyntaxOnly": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESNext"
},
"files": [],
"references": [
{
"path": "./package-1"
},
{
"path": "./package-2"
}
]
}
Package-1 package.json
:
{
"name": "package-1",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"typecheck": "tsc"
}
}
Package-1 tsconfig.json
:
{
"extends": "../tsconfig.json"
}
Package-2 package.json
:
{
"name": "package-2",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"typecheck": "tsc"
}
}
Package-2 tsconfig.json
:
{
"extends": "../tsconfig.json"
}
Why doesn't tsc
report errors that exist in the code?
The issue was fixed by removing files
key from the root tsconfig.json
. This is however different than what docs recommend to do.
Another good practice is to have a “solution” tsconfig.json file that simply has references to all of your leaf-node projects and sets files to an empty array (otherwise the solution file will cause double compilation of files). Note that starting with 3.0, it is no longer an error to have an empty files array if you have at least one reference in a tsconfig.json file.