🎯

type-checking-vs-testing

🎯Skill

from marius-townhouse/effective-typescript-skills

VibeIndex|
What it does

Guides developers in strategically using type checking and unit testing to catch different types of errors and validate code assumptions.

πŸ“¦

Part of

marius-townhouse/effective-typescript-skills(83 items)

type-checking-vs-testing

Installation

Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills --all
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -s prefer-unknown-over-any exhaustiveness-checking
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -a opencode claude-code
Quick InstallInstall with npx
npx skills add marius-townhouse/effective-typescript-skills -l
git cloneClone repository
git clone https://github.com/marius-townhouse/effective-typescript-skills.git
πŸ“– Extracted from docs: marius-townhouse/effective-typescript-skills
1Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

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.

Overview

# 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

```typescript

// 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

More from this repository10

🎯
tsdoc-comments🎯Skill

Generates TypeScript documentation comments (TSDoc) to explain public APIs, complex types, and provide comprehensive code documentation with IDE tooltips.

🎯
async-over-callbacks🎯Skill

Transforms callback-based asynchronous code into clean, readable async/await patterns for better type flow and error handling.

🎯
type-safe-monkey-patching🎯Skill

Enables type-safe runtime extension of global objects and DOM elements in TypeScript without sacrificing type checking or using `as any`.

🎯
create-objects-all-at-once🎯Skill

Efficiently initializes multiple TypeScript objects simultaneously using concise object literal syntax and spread operators.

🎯
module-by-module-migration🎯Skill

Guides developers through systematic TypeScript module migration, breaking down complex refactoring into manageable, incremental steps.

🎯
ts-js-relationship🎯Skill

Explains TypeScript's relationship to JavaScript, highlighting how it adds static typing and catches errors before runtime while remaining fully compatible with JavaScript code.

🎯
code-gen-independent🎯Skill

Generates JavaScript code despite TypeScript type errors and demonstrates that TypeScript types are erased at runtime, requiring alternative type checking strategies.

🎯
context-type-inference🎯Skill

Helps restore precise type context when extracting values, preventing type inference errors through annotations, const assertions, and type preservation techniques.

🎯
precise-string-types🎯Skill

Enforces strict string type constraints and prevents unintended string type conversions in TypeScript projects.

🎯
type-display-attention🎯Skill

Displays and simplifies complex TypeScript types to improve IDE readability and developer experience.