Skip to content

Instantly share code, notes, and snippets.

@rphlmr
Created August 30, 2023 20:56
Show Gist options
  • Save rphlmr/405209fbe96635e05033680af61ed9e6 to your computer and use it in GitHub Desktop.
Save rphlmr/405209fbe96635e05033680af61ed9e6 to your computer and use it in GitHub Desktop.
Keep skipLibCheck to false and still typecheck your project's .d.ts files
#!/bin/bash
RED="\e[31m"
ENDCOLOR="\e[0m"
echo "⏳ Checking for type errors..."
# Run tsc and capture the output
TYPE_ERRORS=$(tsc --project ./tsconfig.json 2>&1)
# Clean node_modules related errors because we use skipLibCheck:false
CLEAN_ERRORS=$(echo "$TYPE_ERRORS" | sed -e '/node_modules/,/node_modules/ d')
# Print the cleaned output
if [[ -n $CLEAN_ERRORS ]]; then
printf "${RED}❌ Type errors were found${ENDCOLOR}\n"
echo "$CLEAN_ERRORS"
exit 1
fi
echo "✅ No type errors found"
exit 0
@rphlmr
Copy link
Author

rphlmr commented Aug 30, 2023

In your package.json, add this script:

"scripts": {
	...
	"typecheck": "sh ./typecheck.sh"
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment