diff --git a/frontend/package.json b/frontend/package.json index 4a57943602..c104f3715b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -210,7 +210,8 @@ }, "lint-staged": { "*.(js|jsx|ts|tsx)": [ - "eslint --fix" + "eslint --fix", + "sh scripts/typecheck-staged.sh" ] }, "resolutions": { diff --git a/frontend/scripts/typecheck-staged.sh b/frontend/scripts/typecheck-staged.sh new file mode 100644 index 0000000000..ea4fdaad86 --- /dev/null +++ b/frontend/scripts/typecheck-staged.sh @@ -0,0 +1,25 @@ +files=""; + +# lint-staged will pass all files in $1 $2 $3 etc. iterate and concat. +for var in "$@" +do + files="$files \"$var\"," +done + +# create temporary tsconfig which includes only passed files +str="{ + \"extends\": \"./tsconfig.json\", + \"include\": [\"src/types/global.d.ts\",\"src/typings/window.ts\", $files] +}" +echo $str > tsconfig.tmp + +# run typecheck using temp config +tsc -p ./tsconfig.tmp + +# capture exit code of tsc +code=$? + +# delete temp config +rm ./tsconfig.tmp + +exit $code \ No newline at end of file