Typescript Private or protected member 'something' cannot be accessed on a type parameter

Viewed 448
class SomeClass<T extends string> {
  protected someMethod(): void {

  }

  protected someOtherMethod(): ReturnType<this["someMethod"]> { 
  // Private or protected member 'someMethod' cannot be accessed on a type parameter.ts(4105)


  }
}

Is there any way to reference back the type of protected class member in the class itself?

1 Answers

This can easily solved by using the class name instead of this:

class SomeClass {
  protected someMethod(): void {

  }

  protected someOtherMethod(): ReturnType<SomeClass["someMethod"]> { 

  }
}

Playground Link

Related