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

Object destructuring with default values and string literals. #10589

Closed
denis-mludek opened this issue Aug 29, 2016 · 1 comment
Closed

Object destructuring with default values and string literals. #10589

denis-mludek opened this issue Aug 29, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@denis-mludek
Copy link

TypeScript Version: 2.0

Code

interface Foo {
  bar?: 'baz' | 'boz'
}

function x(params: Foo) {
  // doesn't work
  const { bar = 'baz' } = params
}

function y(params: Foo) {
  // works
  const { bar = 'baz' as 'baz' } = params
}

Expected behavior:
To compile

Actual behavior:
error TS2322: Type 'string' is not assignable to type '"baz" | "boz"'. Type 'string' is not assignable to type '"boz"'.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

This should be working as expected in latest.

@mhegazy mhegazy closed this as completed Sep 29, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Sep 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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

3 participants