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

Skip to content

[non-nullable-type-assertion-style] triggers on as const declaration #2879

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
3 tasks done
leaumar opened this issue Dec 15, 2020 · 0 comments · Fixed by #2881
Closed
3 tasks done

[non-nullable-type-assertion-style] triggers on as const declaration #2879

leaumar opened this issue Dec 15, 2020 · 0 comments · Fixed by #2881
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@leaumar
Copy link

leaumar commented Dec 15, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/non-nullable-type-assertion-style": ["error"]
  }
}
const x = [] as const;
{
    "compilerOptions": {
        "inlineSourceMap": false,
        "moduleResolution": "node",
        "noUncheckedIndexedAccess": true,
        "strict": true,
        "target": "es2020"
    },
    "include": ["src/**/*.ts"]
}

Expected Result

<anything> as const declarations shouldn't trigger a "don't do a type cast where ! is sufficient" warning since as const doesn't remove any nullability, just makes everything deep-readonly.

Actual Result

The rule thinks as const is a typecast removing null from a type:

Use a ! assertion to more succintly remove null and undefined from the type @typescript-eslint/non-nullable-type-assertion-style

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.10.0
@typescript-eslint/parser 4.10.0
TypeScript 4.1.3
ESLint 7.15.0
node 14.15.1
@leaumar leaumar added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Dec 15, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Dec 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants