While attempting to upgrade to TypeScript 3.5, I ran into an issue with a signature that has been overlooked by the ts-compiler, despite being present for years.
A third-party framework (knockoutJS) requires me to pass something that adheres to this:
interface ViewModelFunction {
(params?: any): any;
}
Interestingly, at runtime, it seems to work by implementing something like this:
class MyClass {
public foobar: string;
constructor(params: { foo: string; bar: number }) {
this.foobar = params.foo + params.bar;
}
public doSomething = () => {
return this.foobar.length;
}
}
and then passing MyClass into a function that expects ViewModelFunction as an attribute. Despite the code functioning correctly, this appears to be primarily a TypeScript problem. For some reason, TypeScript 3.5 suddenly recognizes this discrepancy, while previous versions did not allow syntax like:
class MyClass implements ViewModelFunction{...}
Is there a way to convert the Class into the ViewModelFunction interface?