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
prefer-destructuring false Positive when casting result #13678
Comments
Hi @sk-, thanks for the bug report! I'm not sure if this is a bug, but I think it's reasonable to support this use case, either by default or behind an option. Maybe we could check if there are any comments between the There's also a bug that should be certainly fixed: autofix removes that comment, which should never happen. At least the rule shouldn't auto-fix this code. |
Would the following be equivalent to the original code? const { transactionData } =
/** @type {{ transactionData: Transaction }} */
(data); |
@mdjermanovic yes, that works, but in that case we lose all the benefits of destructuring, as const transactionData =
/** @type {Transaction} */
(data.transactionData); vs const { transactionData } =
/** @type {{ transactionData: Transaction }} */
(data); The second option is even more verbose, as there are 2 extra |
Thanks for clarifying! Then, I think this isn't a bug, but I'll support a configuration option to not report an error if there are any comments inside the declaration/assignment. Let's see if this enhancement will reach a consensus from the team. I'm working on the autofix bug separately. |
Is it a stylistic rule? it is in the category of es6 but It does works for stylistic preference I suppose. If not, IMO, it should be in jsdoc-plugins right ? cause js doesn't understand that typecasting using comments. WDYT ? |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Tell us about your environment
What parser (default,
@babel/eslint-parser
,@typescript-eslint/parser
, etc.) are you using?default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
Not to complain about destructuring
What actually happened? Please include the actual, raw output from ESLint.
Are you willing to submit a pull request to fix this bug?
Depending on whether I'm pointed in the right direction.
The text was updated successfully, but these errors were encountered: