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

Bad inference for destructured object parameter with default value #22644

Closed
OliverJAsh opened this issue Mar 16, 2018 · 3 comments
Closed

Bad inference for destructured object parameter with default value #22644

OliverJAsh opened this issue Mar 16, 2018 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@OliverJAsh
Copy link
Contributor

TypeScript Version: 2.7.2

Search Terms: object literal parameter inference destructuring default value

Code

const fn1 = (options: { headers?: {} }) => {};
// No error as expected
fn1({ headers: { foo: 1 } });

const fn2 = ({ headers = {} }) => {};
// Unexpected error: Property 'foo' does not exist on type '{}'.
fn2({ headers: { foo: 1 } });
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 16, 2018
@RyanCavanaugh
Copy link
Member

Regression from 2.6 -> 2.7

@ahejlsberg ahejlsberg self-assigned this Mar 17, 2018
@ahejlsberg
Copy link
Member

This is an issue exposed by #19513. We're not properly widening types in types implied by object destructuring patterns. Looks like a fairly simple fix.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Mar 17, 2018
@OliverJAsh
Copy link
Contributor Author

Thank you!

@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 28, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants