mcpField
T
type-checking-vs-testing

type-checking-vs-testing

github.com/marius-townhouseTesting & quality644 installsUpdated 38w ago
Repository

About type-checking-vs-testing

A guidance skill explaining how TypeScript type checking and unit tests catch different errors. It helps developers choose complementary checks rather than treating types as a replacement for tests.

Key features

  1. 01Distinguishes compile-time and runtime errors
  2. 02Explains complementary roles of types and tests
  3. 03Covers logic errors and edge cases

Use cases

  1. 01Choosing between type checks and tests
  2. 02Building a test suite for edge cases

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill type-checking-vs-testing

After installing, type/type-checking-vs-testingin Claude Code to confirm it loaded.

Details

From the project README

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

Comments

Markdown supported