type-checking-vs-testing

Use when deciding between types and tests. Use when catching logic errors. Use when testing edge cases. Use when building test suites. Use when validating assumptions.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "type-checking-vs-testing" with this command: npx skills add marius-townhouse/effective-typescript-skills/marius-townhouse-effective-typescript-skills-type-checking-vs-testing

Understand the Relationship Between Type Checking and Unit Testing

Overview

Type checking and unit testing catch different kinds of errors. Type checking catches type mismatches at compile time. Unit testing catches logic errors and edge cases at runtime. They complement each other - types reduce the need for some tests, but can't replace tests for logic.

When to Use This Skill

  • Deciding between types and tests
  • Catching logic errors
  • Testing edge cases
  • Building test suites
  • Validating assumptions

The Iron Rule

Use types to catch type errors at compile time. Use tests to catch logic errors and edge cases at runtime. They complement each other.

Example

// Type checking catches:
function add(a: number, b: number): number {
  return a + b;
}

add(1, '2'); // Compile error - types don't match

// Tests catch:
function divide(a: number, b: number): number {
  return a / b; // Logic error: no check for division by zero
}

// Type system can't catch this - need tests:
test('divide by zero', () => {
  expect(() => divide(1, 0)).toThrow();
});

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 77: Understand the Relationship Between Type Checking and Unit Testing

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

tsdoc-comments

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

code-gen-independent

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tsconfig-options

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

module-by-module-migration

No summary provided by upstream source.

Repository SourceNeeds Review