Skip to content

Instantly share code, notes, and snippets.

@toy-crane
Created July 28, 2025 09:31
Show Gist options
  • Save toy-crane/86104682e88c093151fdf39315c73cc2 to your computer and use it in GitHub Desktop.
Save toy-crane/86104682e88c093151fdf39315c73cc2 to your computer and use it in GitHub Desktop.
Type check hook example
import json
import sys
import subprocess
import re
try:
input_data = json.loads(sys.stdin.read())
except json.JSONDecodeError as e:
print(f"Error: {e}")
sys.exit(1)
tool_input = input_data.get("tool_input")
file_path = tool_input.get("file_path")
if re.search(r"\.(ts|tsx)$", file_path):
try:
subprocess.run(
[
"yarn",
"type-check",
],
check=True,
capture_output=True,
text=True
)
except subprocess.CalledProcessError as e:
print("▲ TypeScript errors detected - please review", file=sys.stderr)
if e.stdout:
print(e.stdout, file=sys.stderr)
if e.stderr:
print(e.stderr, file=sys.stderr)
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment