Derive type info from a function

yasunoritanaka

Yasunori Tanaka

Posted on July 17, 2020

Derive type info from a function

We can derive type from a function like this.

const createPerson = () => ({
  firstName: 'Yasunori',
  lastName: 'Tanaka',
})

type Person = ReturnType<typeof createPerson>

And then, use that as Person type.

💖 💪 🙅 🚩
yasunoritanaka
Yasunori Tanaka

Posted on July 17, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related