Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jakebailey opened this issue Sep 15, 2022 · 0 comments Β· Fixed by #50816
Labels
Bug A bug in TypeScript
Milestone

Comments

@jakebailey
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
2 participants