Typescript infer function parameters in derived class Typescript infer function parameters in derived class typescript typescript

Typescript infer function parameters in derived class


As the other answer says, this is known issue with TypeScript compiler.

There is a way to provide implementation of MyInterface for which method parameters will be inferred, you just have to use a function that returns an object instead of a class:

interface MyInterface<T> {    open(data: T): void}function createMyObject(): MyInterface<string> {    return {        open(data) { // data type is inferred as string here            const n = data.length;        }    }}