Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--fix for "An explicit null check is required" breaks code #226

Open
verhovsky opened this issue Mar 29, 2022 · 1 comment
Open

--fix for "An explicit null check is required" breaks code #226

verhovsky opened this issue Mar 29, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@verhovsky
Copy link

verhovsky commented Mar 29, 2022

What version of this package are you using?

What operating system, Node.js, and npm version?
macos 12.3
Node: v16.14.2
npm: 8.5.3

What happened?

write this code:

function stuff (arg: string, optionalArg?: string[]) {
  optionalArg = optionalArg || ['some', 'default', 'value']
}

run ts-standard --fix, it turns into

function stuff(arg: string, optionalArg?: string[]) {
  optionalArg = (optionalArg != null) || ['some', 'default', 'value']
}

which is broken because optionalArg = (optionalArg != null) sets optionalArg to true instead of keeping it as-is when it has a truthy value. Also, typescript doesn't even compile the new code because the variable can now be a string[] or boolean.

What did you expect to happen?

Code doesn't get changed or code gets changed to use the ?? operator instead.

Are you willing to submit a pull request to fix this bug?

no

@fasenderos
Copy link

fasenderos commented Aug 23, 2023

I reported this bug to typescript-eslint, resolved in v6.4.0.
Also request an update to eslint-config-standard-with-typescript which update only the devDep (not the peerDep) on v38.0.0.

@theoludwig @lindluni @LinusU
Updating both the dependencies ensure that a code fix does not break app functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

3 participants