Actually, there appears to now be a simple way. The following code works in TypeScript 1.5:

function sayName({ first, last = 'Smith' }: {first: string; last?: string }): void {
  const name = first + ' ' + last;
  console.log(name);
}

sayName({ first: 'Bob' });

The trick is to first put in brackets what keys you want to pick from the argument object, with key=value for any defaults. Follow that with the : and a type declaration.

This is a little different than what you were trying to do, because instead of having an intact params object, you have instead have dereferenced variables.

If you want to make it optional to pass anything to the function, add a ? for all keys in the type, and add a default of ={} after the type declaration:

function sayName({first='Bob',last='Smith'}: {first?: string; last?: string}={}){
    var name = first + " " + last;
    alert(name);
}

sayName();
Answer from jpadvo on Stack Overflow
🌐
TypeScript Tutorial
typescripttutorial.net › home › typescript tutorial › typescript default parameters
TypeScript Default Parameters
June 2, 2020 - Use default parameter syntax parameter:=defaultValue if you want to set the default initialized value for the parameter. Default parameters are optional.
Discussions

required function parameters with default values
Suggestion 🔍 Search Terms required parameter default value non-optional function ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change t... More on github.com
🌐 github.com
7
December 20, 2021
Conditional parameter with default values
Why not just do an instanceof check on the animal? if(animal instanceof Dog){ return animal.bark() } then you can remove the boolean parameter entirely. More on reddit.com
🌐 r/typescript
13
2
June 29, 2022
VS Code still unable to show default value for optional function parameters after 6 years. Are you ok with that?
This isn't a problem with vscode. In Python, for example, using the Microsoft Python example will show default values for optional function parameters and the types. This is a problem with Typescript and it's language server, which is why the issue was moved from the vscode repo to the Typescript repo. More on reddit.com
🌐 r/vscode
10
3
November 27, 2023
With a functin that has two arguments with default values, what is the best way to call this function with the default value for the first argument but with a new value for the second argument?
Using undefined as an argument value is the correct way to let the parameter get its default. Alternatively you can use an object for your optional parameters (similar to what InTheAtticToTheLeft suggested) which is a little more verbose - in a nice, named parameter kind of way - but doesn't require undefineds in place of unspecified parameters. function myFunc({argOne = 'one', argTwo = 'two'} = {}) { console.log(argOne, argTwo); } myFunc({argOne: 'newOne'}) // newOne two myFunc({argTwo: 'newTwo'}) // one newTwo The example above uses destructuring to allow the properties of the object to be seen as individual variables within the function body. The default empty object accounts for the case when no arguments are provided. myFunc() // one two More on reddit.com
🌐 r/learnjavascript
15
4
April 18, 2024
🌐
HowToDoInJava
howtodoinjava.com › home › typescript › typescript optional and default parameters
TypeScript Optional and Default Parameters (with Examples)
June 23, 2023 - TypeScript allows assigning a default value to a parameter if no value or undefined is provided when invoking the function. We can provide the default values for optional parameters as well as mandatory parameters.
🌐
Mimo
mimo.org › glossary › typescript › optional-parameter
TypeScript Optional Parameter: Syntax, Usage, and Examples
You can provide a default value for an optional parameter. If you don’t pass an argument, TypeScript uses the default value.
🌐
Medium
blake-wood-bst.medium.com › optional-and-default-function-parameters-in-typescript-15ce8475b5c3
Optional and Default Function Parameters in TypeScript | by <Blake†Codez /> | Medium
January 8, 2023 - Optional parameters are great, because we can do different things based on whether a value is passed in or not: // b is an optional parameter function addTwoValues(a: number, b?: number) { // If b is not given, we can just return a by itself; if(!b) return a; // If b is given, we can add and return both a + b; return a + b; } We can also give b a default value if it is not passed in as well!
🌐
Convex
convex.dev › core concepts › functions & methods › optional parameters
Optional Parameters | TypeScript Guide by Convex
Use ? only when the parameter has no default and you want to allow undefined. When working with default parameter values, TypeScript ensures type safety while providing the flexibility of optional arguments.
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_optional_parameters.htm
TypeScript - Optional Parameters
The optional parameters in TypeScript ... when calling the function. When a function is called without argument value for optional parameter, the default value of optional parameter is set to undefined....
Find elsewhere
🌐
Codefinity
codefinity.com › courses › v2 › a5c23211-8dc2-4c4a-9a83-07a51e843ab6 › 22ee44ac-3952-4715-93f5-a0e487b41d5a › 2514af82-5f65-42e6-9010-4fcdb9dc7dab
Learn Default Values | Functions
This function will provide us with a notification of the transaction amount and its description. Users don't always like to provide descriptions for their transactions, so · this field is optional.
🌐
Byby
byby.dev › ts-function-parameters
TypeScript optional, nullable, and default parameters
May 9, 2023 - Note that when you combine optional and default parameters, the default value will be used when the argument is omitted or undefined, but not when it is null. If you want the default value to be used for both null and undefined, you can use the nullish coalescing operator (??) in the function body.
🌐
Java Code Geeks
javacodegeeks.com › home › web development › typescript
TypeScript Optional and Default Parameters - Java Code Geeks
June 29, 2023 - TypeScript enforces a strict rule that an optional parameter cannot have a default value assigned to it. This means that if a parameter is marked as optional using the ? operator, it cannot also have a default value specified.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Default_parameters
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
🌐
Scaler
scaler.com › home › topics › typescript › default and initialized parameters
Default and Initialized Parameters - Scaler Topics
May 4, 2023 - By using this feature, you can declare some parameters in the function optional, so that the user will not be required to pass the value to optional parameters. In the above-given syntax, there are two parameters : par1 is the default parameter, and ...
🌐
Tim Mousk
timmousk.com › blog › typescript-default-parameter
How To Set A Default Parameter In TypeScript? – Tim Mouskhelichvili
March 6, 2023 - If an optional parameter has no value, the parameter's value is undefined. If a default parameter has no value, the parameter's value is the default value. Default parameters are set using the assignment operator (=). Here is an example of a ...
🌐
Tektutorialshub
tektutorialshub.com › home › typescript › default parameters in typescript
Default Parameters in TypeScript - Tektutorialshub
March 15, 2023 - The default parameters in TypeScript allow us to initialize parameters with default values if no value or undefined is passed as argument.
🌐
Skypoint
skypoint.ai › home › typescript default parameters and destructuring as a substitute for named parameters
TypeScript Default Parameters and Destructuring As a Substitute for Named Parameters - Skypoint
September 23, 2022 - To work around this limitation of JavaScript we can use destructuring to handle our default values and the power of TypeScript to manage our required parameters. First I’ll start by creating an interface for our function parameters. My interface will define the parameter names and their types. I can’t include default values here since the interface will be discarded in the transpiled JavaScript. interface AddToCartParameters { product: string; price: number; quantity?: number; currency?: string; } I’ll use the question mark to indicate the optional parameters.
🌐
Rip Tutorial
riptutorial.com › optional and default parameters
TypeScript Tutorial => Optional and Default Parameters
Optional parameters must come after all non-optional parameters: function buildName(firstName?: string, lastName: string) // Invalid ... If the user passes undefined or doesn't specify an argument, the default value will be assigned.
🌐
Squash
squash.io › how-to-set-default-values-in-typescript
How to Set Default Values in TypeScript - Squash Labs
October 14, 2023 - In the above example, the name parameter is optional, and the greeting parameter has a default value of "Hello". If no value is provided for name, it will default to "World". If no value is provided for greeting, it will default to "Hello".
🌐
Medium
medium.com › @kidaneberihuntse › simplifying-typescript-functions-with-default-parameter-values-d07bc6c54fa3
Simplifying TypeScript Functions with Default Parameter Values | by Kidu BT | Medium
March 29, 2024 - Let’s dive into how these features work together to streamline function declarations. To set a default value for a function parameter in TypeScript, you simply assign the default value directly in the parameter declaration.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-object-parameter-default-value
How to set Default Parameters in TypeScript | bobbyhadz
The getPerson function takes an object as a parameter, and the object has an optional property name. If the name property is not provided when calling the getPerson function, we default it to "Bobby". Note that it's very important to use the question mark to set the name property as optional. If the property is not set as optional, TypeScript will expect you to pass it every time you call the function.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 47202
required function parameters with default values · Issue #47202 · microsoft/TypeScript
December 20, 2021 - Even when the type of the parameter is explicitly defined, it can still be undefined when it has a default value. This is because an argument being optional is tightly coupled with it having a default value.
Author   VanCoding