{"id":4437,"date":"2026-07-27T11:24:41","date_gmt":"2026-07-27T09:24:41","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=4437"},"modified":"2026-07-27T11:24:41","modified_gmt":"2026-07-27T09:24:41","slug":"is-it-safe-to-delete-this-file-how-npx-tsc-noemit-can-save-your-day","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2026\/07\/27\/is-it-safe-to-delete-this-file-how-npx-tsc-noemit-can-save-your-day\/","title":{"rendered":"Is it safe to delete this file? How npx tsc &#8211;noEmit can save your day"},"content":{"rendered":"\n<h4>The situation<\/h4>\n\n\n\n<p>You&#8217;re refactoring. A large <code>models.ts<\/code> file has grown too big \u2014 it mixes enums, interfaces, and types all in one place. Your team agrees: it&#8217;s time to split it into dedicated files (<code>*.enums.ts<\/code>, <code>*.types.ts<\/code>, <code>*.interfaces.ts<\/code>).<\/p>\n\n\n\n<p>You create the new files, update the <code>index.ts<\/code> barrel, and everything <em>looks<\/em> fine. But then comes the question that every developer knows:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><em>&#8220;Can I safely delete the original file now?&#8221;<\/em><\/p><\/blockquote>\n\n\n\n<p>Maybe some file somewhere still imports directly from the old path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ somewhere deep in your codebase...\nimport { IUploadState } from '..\/models\/upload.models';<\/code><\/pre>\n\n\n\n<p>Instead of the new barrel:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { IUploadState } from '..\/models';<\/code><\/pre>\n\n\n\n<p>If you just delete the file and find out later, you&#8217;ll get a runtime crash \u2014 or worse, a broken build in CI.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4>Step 1 \u2014 Hunt down direct imports with <code>grep -r<\/code><\/h4>\n\n\n\n<p>Before touching anything, run a quick search across your entire <code>src\/<\/code> folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -r \"upload.models\" src\/<\/code><\/pre>\n\n\n\n<p><code>grep -r<\/code> recursively searches all files in a directory for a given string. It&#8217;s fast, it&#8217;s reliable, and it immediately tells you if any file still references the old module path.<\/p>\n\n\n\n<p><strong>No output = no direct imports found.<\/strong> You&#8217;re already in good shape.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4>Step 2 \u2014 Verify type consistency with <code>npx tsc --noEmit<\/code><\/h4>\n\n\n\n<p><code>grep<\/code> checks file references, but it doesn&#8217;t understand TypeScript. To make sure your entire type graph is still coherent after the refactor, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npx tsc --noEmit<\/code><\/pre>\n\n\n\n<p>Here&#8217;s what each part does:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>Role<\/th><\/tr><\/thead><tbody><tr><td><code>npx<\/code><\/td><td><em>Runs a binary \u2014 from <code>node_modules<\/code> if installed, or downloads it temporarily from the npm registry if not<\/em><\/td><\/tr><tr><td><code>tsc<\/code><\/td><td>The TypeScript compiler<\/td><\/tr><tr><td><code>--noEmit<\/code><\/td><td>Compiles everything <strong>in memory only<\/strong> \u2014 no files are generated or modified<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Think of it as a <strong>dry run<\/strong> of your entire TypeScript compilation. It reads every file, resolves every import, checks every type \u2014 and reports errors without touching your <code>dist\/<\/code> folder.<\/p>\n\n\n\n<p>If you had missed a stale import, you&#8217;d see something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>error TS2307: Cannot find module '..\/models\/upload.models'\nor its corresponding type declarations.<\/code><\/pre>\n\n\n\n<p><strong>Empty output = zero errors = your codebase is fully consistent.<\/strong> ?<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4>When should you use <code>npx tsc --noEmit<\/code>?<\/h4>\n\n\n\n<p>It&#8217;s not just for file deletions. Reach for it whenever you:<\/p>\n\n\n\n<ul><li><strong>Refactor<\/strong> module structure (splitting, renaming, moving files)<\/li><li><strong>Rename<\/strong> an interface or type used across multiple files<\/li><li><strong>Upgrade<\/strong> a library and want to check for breaking type changes<\/li><li>Want a <strong>fast type-check in CI<\/strong> without triggering a full build<\/li><\/ul>\n\n\n\n<p>It&#8217;s faster than <code>ng build<\/code>, lighter than running tests, and gives you immediate, precise feedback on your type safety.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4>TL;DR<\/h4>\n\n\n\n<p>Whenever you restructure your codebase, make it a habit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. Check for stale path references\ngrep -r \"old-file-name\" src\/\n\n# 2. Verify full type consistency\nnpx tsc --noEmit<\/code><\/pre>\n\n\n\n<p>Two commands. Thirty seconds. Zero surprises.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><em>Tags: <code>#TypeScript<\/code> <code>#Angular<\/code> <code>#Refactoring<\/code> <code>#DeveloperTools<\/code> <code>#WebDev<\/code> <code>#CleanCode<\/code> <code>#Frontend<\/code> <code>#tsc<\/code> <code>#CLI<\/code><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The situation You&#8217;re refactoring. A large models.ts file has grown too big \u2014 it mixes enums, interfaces, and types all in one place. Your team agrees: it&#8217;s time to split it into dedicated files (*.enums.ts, *.types.ts, *.interfaces.ts). You create the new files, update the index.ts barrel, and everything looks fine. But then comes the question [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1965,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37],"tags":[40,1169,776,955,736,1167,161,217,1170,87,1168],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4437"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=4437"}],"version-history":[{"count":1,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4437\/revisions"}],"predecessor-version":[{"id":4438,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4437\/revisions\/4438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1965"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=4437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=4437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=4437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}