TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Empty binding pattern in optional parameter declaration says "Object is possibly 'undefined'", while non-empty does not

Open jakebailey opened this issue 3 years ago • 0 comments

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

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.

jakebailey avatar Sep 15 '22 17:09 jakebailey