Typescript "as const" false positive

  • versions used SonarQube: 1.34.2
  • minimal code sample to reproduce (with analysis parameter, and potential instructions to compile).
const a = ['a', 'b'] as const;

SonarQube reports this Typescript as unnecessary cast. “as const” is a special case of “as” and should not error in this context.

Hello Guy,

Welcome back to the SonarSource community forum!

I am not able to reproduce the false-positive with the latest version of SonarQube. You mentionned using SonarQube 1.34.2, but that version doesn’t exist.

Please clarify your SonarQube setup including the analysis properties.

Regards,
Yassin