TypeScript
TypeScript copied to clipboard
Empty binding pattern in optional parameter declaration says "Object is possibly 'undefined'", while non-empty does not
Bug Report
🔎 Search Terms
empty optional property binding pattern destructuring element
🕗 Version & Regression Information
- This is the behavior in every version I tried.
⏯ Playground Link
💻 Code
declare function fn1({}?: { x: string }): void; // error
declare function fn2({ x }?: { x: string }): void; // OK?
declare function fn3([]?: [ x: string ]): void; // error
declare function fn4([ x ]?: [ x: string ]): void; // OK?
🙁 Actual behavior
An empty binding pattern gets the error Object is possibly 'undefined'., but a non-empty one doesn't.
🙂 Expected behavior
Consistently no error; see also the discussion on #50707.