We want to do a full TypeScript type check of the project before any .tsx? files is committed, typically we use tsc -p . --noEmit.
However if we integrate this command into lint-staged like this:
{
"lint-staged": {
"*.{ts,tsx}": "tsc -p . --noEmit"
}
}
we got an error from tsc:
git commit
husky > npm run -s precommit (node v8.9.4)
❯ Running tasks for *.{ts,tsx}
✖ tsc -p . --noEmit
→ error TS5042: Option 'project' cannot be mixed with source files on a command line.
✖ tsc -p . --noEmit found some errors. Please fix them and try committing again.
error TS5042: Option 'project' cannot be mixed with source files on a command line.
husky > pre-commit hook failed (add --no-verify to bypass)
lint-staged: v6.0.0lint-staged adds staged files as argument to your command, so there is a conflict of . and how lint-staged works. This is why you see this error. You should either do -p . and run it on precommit without lint-staged, or remove -p option.
Regarding the feature request. There is a duplicate issues #138 and #404 so I'm closing this one.
For those that have arrived here in search of type-check TypeScript files on pre-commit hooks, see the gist below.
https://gist.github.com/dcurletti/89edd6a5b329fa01faf39148ffafa71a