Skip to content

Instantly share code, notes, and snippets.

@rileyhilliard
Last active March 12, 2020 12:41
Show Gist options
  • Save rileyhilliard/da10fe11b68d1b7feb31ad119c59d516 to your computer and use it in GitHub Desktop.
Save rileyhilliard/da10fe11b68d1b7feb31ad119c59d516 to your computer and use it in GitHub Desktop.
const person = { first: 'John', last: 'Doe' };
/* -- Correct TypeScript Functional Destructure -- */
// Define a 'Person' interface with the shape of
// the expected Person object argument
interface Person {
first: string;
last: string;
}
// define that the structure of the argument being destructed
// should match the object schema of the Person interface
const hello = ({ first, last }: Person) =>
`Hello ${first} ${last}!`;
// outputs "Hello John Doe!"
hello(person);
@zahmadsaleem
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment