We are an academic group maintaining a TS project. We decided to enforce ESLint rules recently and one of the rules suggested us to change from shorthand method signature (func(arg0: object): number) to (func: (arg0: object) => number) .
I know the following description will be confusing, I attempted to create a minimal reproduction, but attempts were futile as I could not reproduce the issue where generic type could not be correctly inferred.
(This is the permalink of the repo/code where the issue arises)
In short, we have a class and a member function with this signature:
export class Bank<T extends Reactor, S> {
private readonly members = new Array<T>();
//......
public port<P extends Port<unknown> | MultiPort<unknown>>(selector: (reactor: T) => P): P[] {
return this.members.reduce((acc, val) => acc.concat(selector(val)), new Array<P>(0));
}
}
And this interface. which we changed according to ESLint suggestion:
interface IOPortManager<T> extends TriggerManager {
// Version A
- addReceiver(port: WritablePort<T>): void;
// Version B
+ addReceiver: (port: WritablePort<T>) => void;
}
We have a test that goes like this:
class MultiPeriodic extends Reactor {
o = new OutMultiPort<number>(this, 2);
//...
}
const d = new Bank<MultiPeriodic>(/*...*/);
// d.members is MultiPeriodic[]
const func = (member: MultiPeriodic) => member.o;
this.d.port(func); // Errors
If we have the interface with version A declaration we have no issue. If we have version B, then the error message is:
[1/2]