'How can a type of a class field that is unknown at instantiation be inferred?

Here's a class example:

class Foo {
  item: unknown

  constructor(item: unknown) {
    this.item = item 
  }

  getItem(): typeof this.item {
    return this.item
  }
}

Playground

It throws an error: Return type of public method from exported class has or is using private name 'this'

How otherwise can I type return value of getItem if it's unknown?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source