Here is an example to consider:
interface Parameters {
label: string;
quantity?: number;
}
const defaultSettings = {
label: 'Example',
quantity: 10,
};
function setup({ label, quantity }: Parameters = { ...defaultSettings }) {
console.log('setup, label:', label);
console.log('setup, quantity:', quantity);
return;
}
setup();
setup({ label: "Test"});
Playground Link: Provided
The output is as follows:
[LOG]: "setup, label:", "Example"
[LOG]: "setup, quantity:", 10
[LOG]: "setup, label:", "Test"
[LOG]: "setup, quantity:", undefined
Is there a way to specify a default value for the quantity
attribute if not provided?