Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destructuring assignment with rename and typing information

How do I destructure a variable into a new name while keeping typing information?

renderItem({item:'apple'})

// jsx:
function renderItem({item: region}) {
    // region == 'apple'
    return <div>{region}</div>;
}

The above will destructure an object with item and assign it to region.

How do I express typing information for this function signature?

like image 487
Jordan Avatar asked Dec 11 '22 06:12

Jordan


1 Answers

Type the incoming item like so:

function renderItem({item: region}:{item:string}){}
like image 108
Jordan Avatar answered Dec 12 '22 19:12

Jordan