1

I'd like to find a syntax that would make the following code work:

interface ValueAccessor<TValue> {
  returnValue(): TValue;
}

class Caller<TAccessor extends ValueAccessor> {
  public callAccessor<TValue>(accessor: TAccessor<TValue>): TValue {
    return accessor.returnValue();
  }
}

I'd like to keep the TAccessor type "generic" so that we can call the callAccessor method with any concrete implementation of ValueAccessor, whathever the type of the TValue.

Currently, I get the following compilation error on the Caller class definition:

Generic type 'ValueAccessor<TValue>' requires 1 type argument(s).ts(2314)
Friedrik
  • 389
  • 1
  • 2
  • 12
  • There is no direct support in TypeScript for this; see the linked question and its answers, as well as [ms/TS#1213](https://github.com/microsoft/TypeScript/issues/1213), for more information. – jcalz Jul 19 '23 at 00:18

0 Answers0