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) // 0All lessons in this course
- Object Destructuring Types
- Array and Tuple Destructuring
- Default Values in Destructuring
- Nested Destructuring Patterns