
A great way to prevent TypeScript compilation errors from bringing down your CI pipelines is to introduce a type check before you commit your .ts f...
For further actions, you may consider blocking this person and/or reporting abuse
@martinsjastad, I read your article a few months ago and was all hyped on tsc-files. I set it up and used it in Production until today when I came to the hard conclusion that it simply does not help identify errors in other files.
So, for example, if you change the way an export works in FileA and commit your code, any files importing FileA will likely all be broken, and you will not be notified of the breakage until you deploy it.
It is for this reason that I instead added a Husky pre-commit hook to my project that executes
npx tsc
on commit and fails the commit if any errors are found.I hope this helps someone. :)
I was looking for something like lint-staged but then I thought exactly the same thing. It is not helpful for validating TS.
Hello @fatedx so by this, your pre commit hook runs on all files be it staged or unstaged ? In order to catch that import error.
Can you explain how did you do that?
Would this check the types of other files affected by changes to the
staged
files?Hmm I don't think it would as it specifically looks at staged - worth investigating though!
@samueldjones you made my day !
I added it to lint-staged config (custom d.ts file for import with files like
.vue
;) ) and it works !Really thanks you.
Thanks! Exactly what i was looking for!
What if there are let's say 10 staged
*.ts
files and all of them have type errors? Will this solution type check all 10 files or throws an error after the first one and skips the rest?My solution
This works, but only if your codebase is small. I tried implementing this with Husky and lint-staged and made VS Code super slow.