Last active
February 15, 2019 05:25
-
-
Save hhyyg/87c760941947aa7216d764bc9237609f to your computer and use it in GitHub Desktop.
TypeScript: Spread Operator(Object spread, Destructuring)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PersonA { | |
name: string, | |
group: string, | |
item1: string, | |
item2: string, | |
} | |
interface PersonB { | |
name: string, | |
group: string, | |
itemOne: string, | |
itemTwo: string, | |
} | |
const personA: PersonA = { | |
name: 'name', | |
group: 'group', | |
item1: 'item1', | |
item2: 'item2', | |
} | |
const { | |
item1, | |
item2, | |
...partialPersonA | |
} = personA; | |
const personB: PersonB = { | |
...partialPersonA, | |
itemOne: personA.item1, | |
itemTwo: personA.item2, | |
} | |
console.log(personB) | |
/* | |
group: "group" | |
itemOne: "item1" | |
itemTwo: "item2" | |
name: "name" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment