Skip to content

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

Closed

Description

@shovon

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;
}

Activity

  1. mhegazy commented on Jun 26, 2016

    @mhegazy
    Contributor

    Yui (@yuit) can you take a look.

  2. shovon commented on Jun 26, 2016

    @shovon
    Author

    Yui (@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`
  3. changed the title [-]Object dstructuring broken: variables are bound to the wrong object[/-] on Jun 27, 2016
  4. yuit commented on Jun 27, 2016

    @yuit
    Contributor

    Sal Rahman (@shovon) I got the fix for the first comment. I am investigating your second comment

  5. added
    Fixed
    on Jun 28, 2016
  6. yuit commented on Jun 29, 2016

    @yuit
    Contributor

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

  7. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugFixed

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions