8000 [consistent-type-assertions] Disable check as const if assertionStyle: never · Issue #992 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

[consistent-type-assertions] Disable check as const if assertionStyle: never #992

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
cevek opened this issue Sep 20, 2019 · 5 comments · Fixed by #1713
Closed

[consistent-type-assertions] Disable check as const if assertionStyle: never #992

cevek opened this issue Sep 20, 2019 · 5 comments · Fixed by #1713
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@cevek
Copy link
cevek commented Sep 20, 2019

Repro

{
  "rules": {
    "@typescript-eslint/consistent-type-assertions": ["error", { "assertionStyle": "never" }]
  }
}
const x = {a: «foo»} as const

Expected Result
No error
Actual Result
error Do not use any type assertions
Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.3.1
@typescript-eslint/parser 2.2
TypeScript 3.6
ESLint 6.3
node 12
npm 6
@cevek cevek added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Sep 20, 2019
@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Sep 23, 2019
@a-tarasyuk
Copy link
Contributor

@bradzacher

Is it a bug or need to add a new option to handle as const (<const>) assertion for { "assertionStyle": "never" }?

Right now the following code with the option { "assertionStyle": "never" } reports error,

const x = [1] as const;

Is it the right behavior? Or need to ignore const assertion for option { "assertionStyle": "never" } and the following code should be valid?

// @typescript-eslint/consistent-type-assertions": ["error", { "assertionStyle": "never" }]
const x = [1] as const;
const y = { a: 1 } as const;

@bradzacher
Copy link
Member

I'm still undecided tbh.
Technically this is a "safe" assertion, but it is an assertion none the less.

I can see arguments going both directions, but I think this is probably safe to allow in the rule as a special case, considering it cannot ever weaken any typings.

@bradzacher bradzacher added bug Something isn't working and removed enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Sep 30, 2019
@ark120202
Copy link

One problem is that with "assertionStyle": "never" there is no way to specify whether <const>{} or {} as const should be preferred, so that's another point for discussion in #709

@bradzacher
Copy link
Member

yeah. I really wish there was a compiler-level flag for disabling angle-bracket assertions... I mean there kind is (by renaming the file to .tsx), but it seems like it should just be "blockable".

I was thinking maybe we bring back the old rule, or maybe we add more options to this rule to make it more flexible.
It probably requires a bit of a rework / rethink. I don't know how valuable it is to allow linting against angle bracket assertions whilst blocking all assertions - there's only really been one person asking for it.

@garyking
Copy link
Contributor

Please allow an option to specifically disable checks for as const, even when using never.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Mar 24, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
0