#How to get ReturnType of function with specific generic parameter provided?

1 messages · Page 1 of 1 (latest)

lunar geyser
#

Hello, I have generic function, and I need to derive type from it's return type, but using ReturnType<Fn> helper can return only Generic union of types, instead of type with specified generic parameter. Is there a way to extract exact value that function will return?

E.g.

import type { FUNC } from "../impl.ts";

export type Bar = keyof ReturnType<FUNC>
export type AnotherType = keyof ReturnType<FUNC>[Bar];

export type Zee<B extends Bar> = [B] extends [`${string}test${string}`] : "test" : "nope";
export type Foo<A extends AnotherType, G extends boolean> = ReturnType<FUNC>[Zee<B>][[A] extends [AnotherType] ? A : "xxx"]];

The problem here is FUNC is generic type, and Foo depends on G parameter, I need to provide to ReturnType<FUNC> somehow.

#

Oh, so ReturnType<FUNC>[G] works for some reason. Does ReturnType returns object of resolved generics?

#

!solved