SonarJS icon indicating copy to clipboard operation
SonarJS copied to clipboard

Create rule: Assertions comparing incompatible types should not be made

Open nicolas-harraudeau-sonarsource opened this issue 4 years ago • 2 comments

One needs to be careful when reporting the textual representation of a type inferred by TypeScript's compiler. For example, TypeScript would return { a: A, ..., z: Z }[] for the expression [{ a: A(), ..., z: Z() }] while object[] not only is shorter but also more meaningful from JavaScript developer's perspective. In that regard, we need to normalise the types before reporting them. To do so, one can take inspiration from function-return-type, extract that piece of code into a reusable helper function, and eventually extend it.

I created draft PR #2848 , which is unfinished. We currently don't support type resolution in the new test framework. I decided to postpone this rule for later.

saberduck avatar Oct 28 '21 09:10 saberduck