Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check typescript type before commit?

Tags:

git

typescript

I want to check typescript type before commit, So i use tsc --noEmit $(changedFile). However, This command can not specify config file.

I found --project option, But this option will check entire project and i just want to check changedFile, Because some old files has type error but do not need to handle.

So how can i only check changedFile type before commit ?

like image 951
Mebtte Avatar asked Jul 12 '26 14:07

Mebtte


1 Answers

You can use an awesome tool called lint-staged.
This library lint your files before each commit. https://github.com/okonet/lint-staged

Installation

npx mrm lint-staged

Usage for TypeScript

// lint-staged.config.js
module.exports = {
  '**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit'
}
like image 78
David Leuliette Avatar answered Jul 15 '26 04:07

David Leuliette



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!