How does Typescript: get the return type of a generic function?

suppose I have an interface and a generic function

const unused = foo<number>()
declare const a: typeof unused
// a: SimpleRecord<number>[]

but a function call will be triggered. If foo has side effects, it will get rid of.

so ask me, how exactly can I achieve type ret < T > = ReturnType < typeof foo < T > ?

Mar.24,2021

declare function foo<T>():T[];

return generics? I think your problem description is a little confused.
just say your input and expected output


interface SimpleRecord<T> { prop: T }

type Foo<T> = () => SimpleRecord<T>[];

declare function foo<T>(): ReturnType<Foo<T>>;

let a: ReturnType<Foo<string>>;
//a: SimpleRecord<string>[]

I don't know if this is what you want

Menu