Reliably run TypeScript type-checking (npx tsc --noEmit) by using shell_agent as a fallback when run_shell fails due to environment or timeout issues.
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-typescript-typecheck-fallback-a9e587ffbb22 ,按照其中的说明把「typescript-typecheck-fallback」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
When verifying TypeScript compilation as part of a build or validation workflow, run_shell may fail with unknown errors due to shell environment issues, missing PATH entries, timeout constraints, or other transient problems. This skill describes a two-step pattern: attempt the check with run_shell first, then fall back to shell_agent if it fails.
run_shell returns an unexpected or unclear error for a tsc invocation.run_shell (fast path)Try the direct command first. This is fast and gives immediate output when the environment is well-configured.
run_shell: npx tsc --noEmit
Evaluate the result:
shell_agent (reliable path)When run_shell fails in an ambiguous or environmental way, delegate to shell_agent with a natural-language task. shell_agent can autonomously:
npx/tsc binaryTask string to pass to shell_agent:
Run `npx tsc --noEmit` in the project root and report all TypeScript type errors found. If there are no errors, confirm the compilation succeeded. If tsc is not available, attempt to install TypeScript locally with `npm install --save-dev typescript` first.
Evaluate the result:
tsconfig.json missing → Ensure the file exists in the project root before re-running.run_shell("npx tsc --noEmit")
│
├─ success (exit 0) ──────────────────► ✅ PASS
│
├─ type errors reported ──────────────► ❌ Fix errors, retry
│
└─ unknown/env error ─────────────────► shell_agent(natural-language task)
│
├─ success ───► ✅ PASS
└─ errors ───► ❌ Fix & retry
# Pseudo-code for an autonomous agent loop
result = run_shell("npx tsc --noEmit", timeout=60)
if result.exit_code == 0:
print("TypeScript check passed.")
elif result.exit_code != 0 and result.stderr contains "TS\d+":
# Real TypeScript diagnostics — surface and fix them
raise TypeScriptError(result.stderr)
else:
# Ambiguous failure — delegate to shell_agent
shell_agent(
task="Run `npx tsc --noEmit` in the project root and report all TypeScript "
"type errors found. If there are no errors, confirm compilation succeeded. "
"If tsc is not available, install it first with `npm install --save-dev typescript`."
)
tsconfig.json: tsc --noEmit requires a valid config. If none exists, generate one first with npx tsc --init.run_shell at least timeout=90.--project tsconfig.json or a path glob to limit what tsc checks if only a subset of files changed.shell_agent for first-time setups: If the project environment is freshly created and dependencies may not be fully installed, start with shell_agent directly to avoid a predictable run_shell failure.This same fallback pattern applies to any build/lint/type-check command that may be sensitive to shell environment:
| Tool | Primary run_shell command | shell_agent fallback task |
|---|---|---|
| TypeScript | npx tsc --noEmit | "Run npx tsc --noEmit and report errors" |
| ESLint | npx eslint src/ | "Run npx eslint on the src directory and report lint errors" |
| Python mypy | python -m mypy src/ | "Run mypy on the src directory and report type errors" |
| Go build | go build ./... | "Run go build and report compilation errors" |
The core principle: run_shell for speed; shell_agent for resilience.