The new ReturnType
in TypeScript 2.8 is a really useful feature that lets you extract the return type of a particular function.
function foo(e:
This is my currently working solution for extracting un-exported internal types of imported libraries (like knex):
// foo is an imported function that I have no control over
function foo(e: T): InternalType {
return e;
}
interface Wrapper {
// wrapped has no explicit return type so we can infer it
wrapped(e: T) {
return foo(e)
}
}
type FooInternalType = ReturnType['wrapped']>
type Y = FooInternalType
// Y === InternalType