0Pricing
TypeScript Academy · Lesson

Default Values in Destructuring

Combine defaults with type annotations safely.

Filling in the Blanks

Destructuring defaults supply a fallback when a property or element is missing or undefined. Combined with TypeScript's inference, they make optional configuration ergonomic and safe.

A Default in Object Destructuring

Write = value after a binding to give it a fallback. If the property is absent or undefined, the default is used instead.

const opts: { count?: number } = {}
const { count = 0 } = opts
console.log(count) // 0

All lessons in this course

  1. Object Destructuring Types
  2. Array and Tuple Destructuring
  3. Default Values in Destructuring
  4. Nested Destructuring Patterns
← Back to TypeScript Academy