javascript:S3403 Strict equality operators should not be used with dissimilar types - redux selector

SonarScanner 4.7.0.2747
Analyzing on SonarQube server 8.9.6

useSelector(getScenario) will resolve to a string value, which is being compared.

// currentSession.js
import { createSlice } from '@reduxjs/toolkit';
export const currentSession = createSlice({
  name: 'currentSession',
  initialState: {
    scenario: 'deactivate',
  },
  reducers: {},
});
export const getScenario = state => state.currentSession.scenario;
export default currentSession.reducer;


// Wizard.js
import { useSelector } from 'react-redux';
import { getScenario } from './currentSession';
function Wizard() {
  const currentScenario = useSelector(getScenario);
  const doThing = () => {
    if (currentScenario === 'deactivate') { // Fail: Remove this "===" check; it will always be false. Did you mean to use "=="?
      console.log('deactivate');
    } else {
      console.log('other scenario');
    }
  };
};

Hi @alex1

Thanks for reporting this. It seems indeed a false positive. We have opened a ticket to track this.

Cheers,
Victor