A resilient workflow for running TypeScript compile checks (tsc --noEmit) that falls back gracefully when npx or direct binary invocations fail, and distinguish
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-typescript-compile-check-resilient-fallback-4737b4478bef ,按照其中的说明把「typescript-compile-check-resilient-fallback」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this workflow whenever you need to verify that TypeScript files compile
cleanly after creating or modifying them, especially in environments where
npx or direct ./node_modules/.bin/tsc invocations may return unexpected
errors.
Run the compile check with run_shell using the standard approach:
npx tsc --noEmit
or, if you already know the project root:
./node_modules/.bin/tsc --noEmit
Evaluate the result:
npx not found,
permission denied, spawn error, unclear non-zero exit unrelated to TS
diagnostics) → proceed to Step 2.shell_agentWhen the primary invocation fails with an unknown error, delegate to
shell_agent so it can resolve environment issues automatically:
Task: "From the project directory
<PROJECT_DIR>, runnode node_modules/typescript/bin/tsc --noEmitand report all TypeScript diagnostic errors."
Example shell_agent task string:
From /path/to/project, run:
node node_modules/typescript/bin/tsc --noEmit
Capture the full stdout/stderr output and return it.
shell_agent will handle PATH issues, working-directory changes, and
retry on transient failures automatically.
TypeScript projects frequently have pre-existing errors in files you did not touch. To avoid false regressions:
all_errors = parse_tsc_output(tsc_stdout)
my_files = [list of files created/modified in this task]
new_errors = [e for e in all_errors if e.file in my_files]
if len(new_errors) == 0:
print("✅ No new TypeScript errors introduced.")
else:
for err in new_errors:
print(f"❌ {err.file}:{err.line} — {err.message}")
raise Exception("Fix TypeScript errors before continuing.")
If new errors are found:
run_shell: npx tsc --noEmit
│
├─ clean exit ──────────────────────────────► ✅ Done
│
├─ TS diagnostic errors ────────────────────► Step 3 (filter)
│
└─ unknown/tool error
│
└─ shell_agent: node .../tsc --noEmit
│
├─ TS diagnostic errors ────► Step 3 (filter)
└─ clean exit ──────────────► ✅ Done
tsconfig.json lives).node node_modules/typescript/bin/tsc invocation is the most portable
fallback because it bypasses npx, shell PATH lookups, and binary
permission issues entirely.