[Fixed] Typescript: type for named arrow function throws TS error for spyOn() in Jasmine unit test


I have this arrow method in my Angular comp

private event_listener_callback = (evt: Event): void => {
   // do something

All working so far.

In a Jasmine unit test where I spy on that arrow function via

spyOn(comp, 'event_listener_callback').and.callThrough();

it throws error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

using @ts-ignore avoids that and the unit test is working correctly.

What would be the correct type for the arrow function to avoid this TS error ?


had to set the property to public for the TS error to go away…

Leave a Reply

(*) Required, Your email will not be published