Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: [prefer-nullish-coalescing] revisit considering any/unknown possibly-nullish #10694

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

Closed
4 tasks done
kirkwaiblinger opened this issue Jan 21, 2025 · 1 comment · Fixed by #10865
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Jan 21, 2025

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/prefer-nullish-coalescing/

Description

In #8262, a bug was fixed around prefer-nullish-coalescing's use of isNullableType(). However, it was mentioned during the PR (and I agree) that we probably should use the behavior in isNullableType() and just adapt the rule implementation details to not crash on it, see #8262 (comment).

Fail

// ignorePrimitives: /* all set to false */
declare const u: unknown;
const foo = u || 'bar'

Pass

// ignorePrimitives: /* all set to false */
declare const u: unknown;
const foo = u ?? 'bar'

// ignorePrimitives: /* any set to true */
declare const u: unknown;
const foo = u || 'bar'

Additional Info

No response

@kirkwaiblinger kirkwaiblinger added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 21, 2025
@kirkwaiblinger
Copy link
Member Author

kirkwaiblinger commented Jan 21, 2025

For reference, this is reported (by default, even):
Playground

declare const basicallyUnknown: null | undefined | string | number | bigint | symbol | object | {} | Function;

basicallyUnknown || 'reported!';

Eslint config

{
  "rules": {
    "@typescript-eslint/prefer-nullish-coalescing": "error"
  }
}

@kirkwaiblinger kirkwaiblinger changed the title Enhancement: [prefer-nullish-coalescing] revisit consider any/unknown possibly-nullish Enhancement: [prefer-nullish-coalescing] revisit considering any/unknown possibly-nullish Jan 21, 2025
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Feb 17, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Mar 14, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants