Connected to SonarCloud or SonarQube (and which version): no
And a thorough description of the problem / question:
Hello, Team!
I noticed that in my project, SonarLint incorrectly identifies an assertion as unnecessary, but it is necessary indeed (see attached file). Can you please fix this? AssertionUnnecessaryIncorrect|690x388 SonarLog.log (7.2 KB)
Hi @Omcsesz, Welcome, and thank you for your feedback.
First, I would like to confirm with you the use-case details. I can reproduce the same behavior by assuming that the signature of jwtDecode() is:
function jwtDecode<T>(token: string): T {}
In this case, the issue appears if we use an as type assertion to specify the function return type. But we can avoid the problem by adding a type annotation to the variable instead.
Thanks for the suggestion @Omcsesz
Before working on this rule, we will wait for more feedback to determine which option is preferable between type annotations and type assertions for functions with a generic return type.
Regards
François