DEV Community

Yasunori Tanaka
Yasunori Tanaka

Posted on

 

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.

Top comments (0)

We're hiring!

We're Hiring

We're looking for someone who can develop, maintain, and implement our product roadmap and strategy as a Senior Product Manager.

Head here to learn more.