When working with TypeScript, you might have noticed something odd:
You delete a
.tsfile — but its compiled.jsand.d.tsfiles are still hanging around in yourdist/folder... 🤨
If you're like me, your first instinct is:
“Wait... shouldn't
tsctake care of this automatically?”
Unfortunately, no.
🤔 Why This Happens
The TypeScript compiler (tsc) compiles .ts files to .js, .d.ts, and .map.js, but it does not clean up old files. If you delete a source file, the compiled version stays in your output directory.
That leftover file might:
- Still get imported
 - Cause your app to crash unexpectedly
 - Create hard-to-track bugs
 - Waste space, especially in limited environments
 
  
  
  🛠️ The Fix: tsc-clear
To fix this, I built tsc-clear:
A lightweight Rust-powered CLI that automatically cleans up your dist/ folder by removing any compiled files (.js, .d.ts, .map.js) that no longer have a corresponding .ts file in your project.
✨ Key Features
- 🧹 Auto-cleans stale files after compilation
 - ⚡ Fast — written in Rust for high performance
 - ⚙️ No configuration needed — reads 
tsconfig.jsonto detect youroutDir - 🪟 Windows only for now (cross-platform support planned)
 
📦 Install It Globally
npm install -g tsc-clear
🚀 Example Usage
Update your package.json scripts like this:
{
  "scripts": {
    "start": "tsc && tsc-clear src && node dist/index.js"
  }
}
tsc-clear runs after tsc and before node, ensuring that your output directory is clean and safe.
🧠 Why I Built It
I was working on a project where I kept removing and renaming files — and everything looked fine... until I ran the app and hit an error caused by a file I had deleted days ago 😵
The old .js file was still sitting in dist/, silently breaking everything.
After searching for a solution and finding nothing lightweight, native, and easy to use — I decided to build tsc-clear for myself.
Now I’m sharing it with you. ✨
✅ TL;DR
- TypeScript doesn't clean up 
dist/ - Old files can break your app or cause unexpected behavior
 - 
tsc-clearsolves this in one command 
🔗 Links
- GitHub Package Repo: github.com/SignorMassimo/tsc-clear
 - GitHub Rust Repo: github.com/SignorMassimo/tsc-clear-rust
 - npm: npmjs.com/tsc-clear
 
Thanks for reading!
Let me know if this tool helped you — or drop a star ⭐ on GitHub if you like it!
Happy coding! 🧼💻
    
Top comments (0)