Closed
Description
Bug Report
When calling a function with an object which has a default parameter and is destructured with fallback values, optional properties are only inferred correctly if that default parameter is created ad-hoc. If it's a function call or variable reference, the optional properties of the parameter are no longer detected.
🔎 Search Terms
function default parameter optional
🕗 Version & Regression Information
- This is the behavior in every version I tried (3.3.3 to Nightly), and I reviewed the FAQ for entries about function calls
⏯ Playground Link
💻 Code
function works({ a, b = true } = { a: true, b: true }) {}
works({a: true});
function defaultParam1() {
return { a: true, b: true };
}
function doesntWork1({ a, b = true } = defaultParam1()) {}
doesntWork1({a: true}); // b wrongfully required
const defaultParam2 = { a: true, b: true };
function doesntWork2({ a, b = true } = defaultParam2) {}
doesntWork2({a: true}); // b wrongfully required
🙁 Actual behavior
Destructuring a function parameter with a default value doesn't mark properties as optional that have a fallback value when the default parameter isn't created ad-hoc.
🙂 Expected behavior
It doesn't make a difference if the default parameter is created ad-hoc or indirectly.