TypeScript typeof Function return value

Original Post

TypeScript < 2.8

I created a little library that permits a workaround, until a fully declarative way is added to TypeScript:

https://npmjs.com/package/returnof

Also created an issue on Github, asking for Generic Types Inference, that would permit a fully declarative way to do this:

https://github.com/Microsoft/TypeScript/issues/14400


Update February 2018

TypeScript 2.8

TypeScript 2.8 introduced a new static type ReturnType which permits to achieve that:

https://github.com/Microsoft/TypeScript/pull/21496

You can now easily get the return type of a function in a fully declarative way:

const createPerson = () => ({
  firstName: 'John',
  lastName: 'Doe'
})

type Person = ReturnType<typeof createPerson>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)