The situation

You’re refactoring. A large models.ts file has grown too big — it mixes enums, interfaces, and types all in one place. Your team agrees: it’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 that every developer knows:

“Can I safely delete the original file now?”

Maybe some file somewhere still imports directly from the old path:

// somewhere deep in your codebase...
import { IUploadState } from '../models/upload.models';

Instead of the new barrel:

import { IUploadState } from '../models';

If you just delete the file and find out later, you’ll get a runtime crash — or worse, a broken build in CI.


Step 1 — Hunt down direct imports with grep -r

Before touching anything, run a quick search across your entire src/ folder:

grep -r "upload.models" src/

grep -r recursively searches all files in a directory for a given string. It’s fast, it’s reliable, and it immediately tells you if any file still references the old module path.

No output = no direct imports found. You’re already in good shape.


Step 2 — Verify type consistency with npx tsc --noEmit

grep checks file references, but it doesn’t understand TypeScript. To make sure your entire type graph is still coherent after the refactor, run:

npx tsc --noEmit

Here’s what each part does:

PartRole
npxRuns a binary — from node_modules if installed, or downloads it temporarily from the npm registry if not
tscThe TypeScript compiler
--noEmitCompiles everything in memory only — no files are generated or modified

Think of it as a dry run of your entire TypeScript compilation. It reads every file, resolves every import, checks every type — and reports errors without touching your dist/ folder.

If you had missed a stale import, you’d see something like:

error TS2307: Cannot find module '../models/upload.models'
or its corresponding type declarations.

Empty output = zero errors = your codebase is fully consistent. ?


When should you use npx tsc --noEmit?

It’s not just for file deletions. Reach for it whenever you:

  • Refactor module structure (splitting, renaming, moving files)
  • Rename an interface or type used across multiple files
  • Upgrade a library and want to check for breaking type changes
  • Want a fast type-check in CI without triggering a full build

It’s faster than ng build, lighter than running tests, and gives you immediate, precise feedback on your type safety.


TL;DR

Whenever you restructure your codebase, make it a habit:

# 1. Check for stale path references
grep -r "old-file-name" src/

# 2. Verify full type consistency
npx tsc --noEmit

Two commands. Thirty seconds. Zero surprises.


Tags: #TypeScript #Angular #Refactoring #DeveloperTools #WebDev #CleanCode #Frontend #tsc #CLI

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist , BizDevOps

Leave a Reply

Your email address will not be published. Required fields are marked *