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 - For example: function applyDiscount(price, discount = 0.05) { return price * (1 - discount); } console.log(applyDiscount(100)); // 95Code language: JavaScript (javascript) In this example, the applyDiscount() function has the discount parameter as a default parameter.
🌐
Mimo
mimo.org › glossary › typescript › default-parameter
TypeScript Default Parameter: Syntax, Usage, and Examples
Default parameters are not included in TypeScript’s type definitions, so calling function.length does not count them. ... function example(a: string, b: number = 10): void {} console.log(example.length); // Output: 1 (not 2)
Discussions

Setting default value for TypeScript object passed as argument - Stack Overflow
How does this apply to the OP's question regarding default value for TypeScript object passed as an argument? You should show an example with an object argument. 2018-01-26T23:56:06.75Z+00:00 ... It doesn't, but I found this question when I was searching for how to provide default parameters in ... More on stackoverflow.com
🌐 stackoverflow.com
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
How to prevent inferring of optional generic?
In the first case, TS replaces unknown with boolean, it wasn't intended, is there any workaround to prevent this? In TypeScript 5.4.0-beta and higher, you can use NoInfer<...> to block this: function raw(str: string): NoInfer> { return { type: {} as T, values() { return this } } } TS playground More on reddit.com
🌐 r/typescript
7
1
February 21, 2024
Interface separation or use optional parameters
The first one is usually more strict, better imo. In the second, you have to do checks in attributes and throws in runtime. The first is also more complex to work with, but if you do everything that way from the start, it shouldn't be a problem. A typical, more como example between create and update, is that update requires an id (specially when talking about DB updates), but create doesn't. So it's common to see an "Update extends Create". More on reddit.com
🌐 r/typescript
13
3
January 17, 2024
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_default_parameters.htm
TypeScript - Default Parameters
Default Parameters should come after Required Parameters in the function definition · In the following example, we put the default parameter y after the required parameter x.
🌐
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 - JavaScript, as well as TypeScript, doesn’t support this kind of assignment in a function call. Instead I’ll need to provide a value for all the parameters preceding currency. ... When I pass a parameter an undefined value JavaScript will use the default value for that parameter.
🌐
typescriptlang.org
typescriptlang.org › docs › handbook › 2 › functions.html
TypeScript: Documentation - More on Functions
Note that we didn’t have to specify Type in this sample. The type was inferred - chosen automatically - by TypeScript. We can use multiple type parameters as well. For example, a standalone version of map would look like this:
🌐
Fjolt
fjolt.com › article › typescript-default-parameters
How TypeScript Default Parameters Work
As such, default parameters let us improve a user’s experience in some cases. They also can be used in other places, such as setting the default position of a shape on an HTML canvas. Fortunately, there isn’t much added complexity in TypeScript when it comes to default parameters.
Find elsewhere
🌐
EDUCBA
educba.com › home › software development › software development tutorials › typescript tutorial › typescript default parameter
TypeScript default parameter | Learn How does default parameter work?
April 6, 2023 - It is not mandatory in TypeScript. Let’s take a closer look at the method signature how it looks like; ... In the above signature, we define one function that takes the default parameter as the input param here. This function is like any normal function in TypeScript.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Codefinity
codefinity.com › courses › v2 › a5c23211-8dc2-4c4a-9a83-07a51e843ab6 › 22ee44ac-3952-4715-93f5-a0e487b41d5a › 2514af82-5f65-42e6-9010-4fcdb9dc7dab
Learn Default Values | Functions
Let's take a look at an example: 123456 function createBankTransaction(amount: number, description: string = "No description provided") { console.log(`Transaction: ${description}, Amount: $${amount}`); } createBankTransaction(100); // No description ...
🌐
Rip Tutorial
riptutorial.com › optional and default parameters
TypeScript Tutorial => Optional and Default Parameters
If the user passes undefined or doesn't specify an argument, the default value will be assigned. These are called default-initialized parameters. For example, "Smith" is the default value for the lastName parameter.
🌐
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 - TypeScript’s type inference capabilities further refine this process, reducing the need for explicit type annotations. 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.
🌐
JavaScript in Plain English
javascript.plainenglish.io › named-typed-parameters-with-default-values-in-typescript-927ae5d6b6af
Named & Typed Parameters with Default Values in TypeScript | by Jeremy Brown | JavaScript in Plain English
January 13, 2025 - For example, if a function has only one parameter, there is not much of a gain in readability by using it. Of course, no article these days would be complete without some mention of ChatGPT. Here is what ChatGPT suggested when prompted with the following question: How can I write a TypeScript constructor or function that accepts typed, keyword arguments with default ...
🌐
Tim Mousk
timmousk.com › blog › typescript-default-parameter
How To Set A Default Parameter In TypeScript? – Tim Mouskhelichvili
March 6, 2023 - In this example, the lastName parameter is an optional parameter with a default value. When we call the outputUser function, we only need to pass an argument for the first parameter.
🌐
Scaler
scaler.com › home › topics › typescript › default and initialized parameters
Default and Initialized Parameters - Scaler Topics
May 4, 2023 - For example, if we define a sub function as sub(x, y): return x-y, then x-y will be the parameters and if we call the above function as sub(5, 4), then 5, 4 will be the arguments.
🌐
Squash
squash.io › how-to-set-default-values-in-typescript
How to Set Default Values in TypeScript - Squash Labs
October 14, 2023 - The greet function has a default parameter of type Person, which means if no object is provided when calling the function, it will use the default value of { name: "John Doe", age: 30 }. Related Article: Tutorial: Extending the Window Object ...
🌐
Programiz
programiz.com › typescript › default-parameters
TypeScript Default Parameters
In the above example, we've kept the default parameter z: number = 10 at the end of the parameter list. As a result, when TypeScript encounters the code sum(5, 15), it clearly knows that x = 5 and y = 15.
🌐
HowToDoInJava
howtodoinjava.com › home › typescript › typescript optional and default parameters
TypeScript Optional and Default Parameters (with Examples)
June 23, 2023 - Similar to optional parameters, ... declaration. In the following example, the function fullName() specifies the default value the last parameter middleName as an empty string....
🌐
Medium
medium.com › @rare › setting-default-values-in-typescript-ac7f31482996
Setting Default Values in TypeScript | by rare. | Medium
May 14, 2024 - interface Superhero { name?: string; skill?: string; isSmart?: boolean; } function describeSuperhero({ name = 'Unknown Hero', skill = 'Unknown Skill', isSmart = false }: Superhero): void { console.log(`Superhero: ${name}. Skill: ${skill}. Smart: ${isSmart}`); } // Example usage: describeSuperhero({}); // Output: Superhero: Unknown Hero. Skill: Unknown Skill. Smart: false describeSuperhero({ name: 'Spider-Man', skill: 'Web-Slinging' }); // Output: Superhero: Spider-Man. Skill: Web-Slinging. Smart: false · We use object destructuring with default values directly in the function parameter list.
🌐
Execute Program
executeprogram.com › courses › advanced-typescript › lessons › default-type-parameters
Advanced TypeScript: Default Type Parameters
Learn programming languages like TypeScript, Python, JavaScript, SQL, and regular expressions. Interactive with real code examples.
🌐
HackerNoon
hackernoon.com › how-to-use-default-parameters-in-typescript
How to Use Default Parameters in TypeScript | HackerNoon
August 21, 2022 - When we talk about default parameters, we are talking about giving arguments values that should be used, if that argument is undefined.