ylliX - Online Advertising Network
How to build GenAI mock server?

Typescript – how to specify generic parameters for an interface method


Considering the following example:

type Foo<T> = (x: T) => T[]
type X = ReturnType<Foo<number>>

As expected, X = number[]

Now, the function is a part of an interface:

interface Bar {
    foo<T>(x: T): T[]
}

type BarFoo = Bar['foo']
type Y = ReturnType<BarFoo<number>>
type Z = ReturnType<Bar['foo']<number>>

Line Y fails with BarFoo is not generic

Line Z fails with a syntax error ('>' expected)

How do I get a specific version of a generic interface method?



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *