Typescript: Argument type string[] is not assignable to parameter type any

Viewed 1428

There is a point I don't understand, in an angular application. Here is my piece of code:

expect(routeurSpy.navigate).toHaveBeenCalledWith(['login'], { queryParams: { returnUrl: 'index' } });

The error Argument type string[] is not assignable to parameter type any appears for both arguments of the toHaveBeenCalledWith method.

I can understand that any cannot be cast to string[], but why can't an array be casted to any?

Note that I could cast explicitely to any, e.g.

expect(routeurSpy.navigate).toHaveBeenCalledWith(['login'] as any, { queryParams: { returnUrl: 'index' } } as any);

But I then have a tslint error because of the no-any rule. And before disabling this rule, I'd like to understand why there is such an error?

0 Answers
Related