DEV Community

Cover image for Strong TypeScript contracts turn refactors into checklists
LkSvn
LkSvn

Posted on

Strong TypeScript contracts turn refactors into checklists

Today a TypeScript refactor produced 15 compiler errors.

It looked worse than it was.

My Candidate Tracker used a type called AsyncResult<T> with errors represented only as strings.

While adding a real PostgreSQL repository, two design problems became clear:

  • the result itself was not asynchronous; the surrounding Promise was
  • an error string discarded its category and original cause I changed the contract to Result<T, E> and introduced a typed RepositoryError.

The compiler immediately identified every repository, dashboard function, test, and callback that still depended on the old contract.

Most of the 15 errors were not separate problems. They were downstream symptoms of a few outdated type definitions.

Once those source contracts were corrected, the remaining errors disappeared and all tests passed again.

The lesson was practical:

Strong types do more than prevent mistakes while writing code. They make architectural changes searchable, explicit, and finite.

Top comments (0)