Imported from prests/.dotfiles (
.agents/skills/typescript-debugging/SKILL.md). Install upstream withnpx skills add prests/.dotfiles --skill typescript-debugging. Copyright stays with the author.
TypeScript Debugging
Use When
- Debugging TypeScript code with proper sourcemap resolution.
- Diagnosing runtime errors that type checking should have caught.
- Inspecting async stack traces and promise rejections.
- Analyzing memory leaks in TypeScript applications.
Setup and Tools
- Sourcemaps
- Ensure
sourceMap: truein tsconfig.json. - Verify
.mapfiles are alongside compiled.jsfiles. - In Node: use
--source-map-supportor thesource-map-supportpackage. - In VS Code: configure
.vscode/launch.jsonwithsourceMapPathOverrideif needed.
- Debugging tools
- VS Code Debugger: Set breakpoints, step through code, inspect variables (native sourcemap support).
- Node.js Inspector:
node --inspectornode --inspect-brkto use Chrome DevTools or VS Code. - Async stack traces: Enable
--stack-trace-async(Node 12+) to see full promise chain.
Checklist
- Type and runtime alignment
- Could a type assertion (
as) or type guard be hiding a real error? - Are runtime values matching their declared types?
- Check for implicit
anytypes or overly permissive unions.
- Async debugging
- Inspect promise rejection handlers; missing
.catch()silently fails. - Use
--stack-trace-asyncfor full async context in crashes. - Verify async function return types are Promise-like, not fire-and-forget.
- Memory and resource leaks
- Check for circular references or retained closures.
- Use VS Code's memory profiler or Chrome DevTools heap snapshots.
- Look for event listeners, timers, or streams that are never cleaned up.
- Module and import issues
- Check sourcemap paths in stack traces; they should point to
.tsfiles. - Verify
moduleResolutionin tsconfig matches your runtime (node, bundler). - Look for circular dependencies or dynamic requires that break at runtime.
Output Requirements
For each finding provide:
- Suspected root cause
- Evidence (stack trace, sourcemap status, type context)
- Steps to confirm with debugger
- Fix strategy with type-safety considerations