Typescript 3.7.2 Null conditional operator on a function call is giving a false positive

  • Versions used: SonarCloud
  • Typescript: 3.7.2

We have a paid subscription with SonarCloud and since we adopted typescript 3.7.2, we get false positives with error being: Non-empty statements should change control flow or have at least one side-effect

The code that’s reported as buggy is this

x?.somefunction("abc") where somefunction property has the following type
(aaa: string) => void

So if the function is defined, it should be called, which is exactly what the ?. does.

Is this a false positive?

Thanks,
Matija

1 Like

Hello Matija,

I guess that you will find something like this in the logs:

WARN: You are using version of TypeScript 3.7.2 which is not officially supported; supported versions >=3.2.1 <3.6.0

The false positive you are facing is a typical consequence of using more recent version, the analysis will probably goes though, but rules may not behave correctly in the presence of new ts features (in this case: optional chaining introduced in ts 3.7).

For the specific case you are reporting, I agree that it looks like a false positive, and in fact it looks like this issue who is already fixed. (typescript-eslint is a dependency used by our plugin).

All in all, this false positive should disappear once we upgrade our dependencies and officially support TS 3.7, it will probably be the case for the next release.

Hope this clarifies the situation.

Quentin

Thanks for the clarification!

Hello, are there updates in Typescript 3.7 support by SonarCloud? When is the next release planned?
We still get false positives which we need to manually resolve every week…

The new version of SonarJs was deployed yesterday on sonarcloud.

However, I was also disappointed to see that, even though we updated versions to a one supposed to include the fix for this fp, it is still here…

This is in fact due to the fact that we are relying on another plugin for this rule, and this plugin does not support correctly optional chaining.

I created a ticket to track this issue, I’m afraid you will have to cope with it a little more. :confused:

Hope it clarify the situation.

Hi Quentin, I see that there is no movement on the github issues. Is there any way in sonarcloud configuration to turn off this check, for this use case? We basically get failing builds every week for no good reason.

Hello,

Is there any way in sonarcloud configuration to turn off this check

You can remove it from your quality profile.
Note that it will remove all issues raised by this rule, including ones unrelated to optional chaining. I don’t see other alternative though.

Here is an example on how to do it:

In addition, I advise you to come back to the original profile once the issue is resolved, to benefit from the latest changes and additions (or regularly check for updates).

Hey, I saw some activity in the github. Is this issue resolved now?

By looking at the ticket, yes, it seems to be finally resolved and will be available for the next release.