Skip to content

Parameter destructuring loses type information #5416

@johnnyreilly

Description

@johnnyreilly

I've just noticed this problem:

var myBooks = [
    {title: 'Sherlock Holmes'},
    {title: 'Moby Dick'}
];

var bookTitles = myBooks.map(({title}) => title); // Boo!  no type information; title is `any`

So if I use parameter destructuring I lose the type information which is kinda sad.

I can work around it like this:

var bookTitles = myBooks.map(b => {
    const { title } = b;
    return title;
}); 

or this:

var bookTitles = myBooks.map(b => b.title); 

But ideally I shouldn't need to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions