What are default parameter values in TypeScript?

Answer

Default parameter values in TypeScript work the same as JavaScript's ES6 default parameters but with type inference. When you provide a default value, TypeScript automatically infers the parameter type from the default: function greet(name: string, greeting = "Hello"): string { return `\${greeting}, \${name}!`; }greeting is inferred as string. The parameter becomes optional from the caller's perspective — you can omit it or pass undefined to use the default. You can combine with explicit types: function setPage(page: number = 1, limit: number = 10) { ... }. Default parameters can reference earlier parameters: function createRange(start: number, end: number = start + 10) { ... }. Unlike optional parameters (?), default parameters do not result in the type being widened to include undefined within the function body — they are guaranteed to have a value.