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 broken: variables are bound to the wrong object #9363

Closed
shovon opened this issue Jun 26, 2016 · 4 comments
Closed

Object destructuring broken: variables are bound to the wrong object #9363

shovon opened this issue Jun 26, 2016 · 4 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@shovon
Copy link

shovon commented Jun 26, 2016

TypeScript Version: 1.8.10

Code

interface ISomething {
    foo: string,
    bar: string
}

function foo({}, {foo, bar}: ISomething) {

}

Expected behavior:

function foo(_a, _b) {
    var foo = _b.foo, bar = _b.bar;
}

Actual behavior:

function foo(_a, _b) {
    var foo = _a.foo, bar = _a.bar;
}
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jun 26, 2016
@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 26, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jun 26, 2016

@yuit can you take a look.

@shovon
Copy link
Author

shovon commented Jun 26, 2016

@yuit fyi, in a function with two parameters, each representing objects with properties that can be destructured, it doesn't matter whether the function expects something or nothing from any of these objects, if either null or undefined is passed in to either of these parameters by the client code, an exception should be raised.

Example:

function something({}, {foo, bar}) {
  // ...
}

function another(viaIdentifier, { foo, bar }) {
  // ...
}

something(undefined, { foo: 'foo', bar: 'bar' });
// This is an ERROR, because the first parameter is set to undefined, and the
// function `something` was declared to have the first parameter be
// destructured, even if we aren't asking for any properties from it

another(undefined, { foo: 'foo', bar: 'bar' });
// This is perfectly fine, because the first parameter is not destructured in
// function declaration of `another`

@shovon shovon changed the title Object dstructuring broken: variables are bound to the wrong object Object destructuring broken: variables are bound to the wrong object Jun 27, 2016
@yuit
Copy link
Contributor

yuit commented Jun 27, 2016

@shovon I got the fix for the first comment. I am investigating your second comment

@yuit
Copy link
Contributor

yuit commented Jun 29, 2016

@shovon I have another PR to fix your second comment, if you would like to take a look !

@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