-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as duplicate
Closed as duplicate
Copy link
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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
Description
As an enhancement of the no-unnecessary-type-conversion rule proposed in #8515 and implemented in #10182, I propose that Object.values(array)
be treated as an unnecessary type conversion as the expression can be simplified to just array
.
Examples:
// fail
Object.values(['a', 'b', 'c']) // simplify to: ['a', 'b', 'c']
const ar = ['a', 'b', 'c']
Object.values(ar) // simplify to: ar
// pass
type MyObject = { a: string }
let arrayOrObject: array | MyObject
arrayOrObject = ['a', 'b', 'c']
Object.values(arrayOrObject) // could be an object, can't simplify
I have discovered Object.values(array)
within my own projects, it is possible this unnecessary type coercion exists elsewhere too.
Fail
Object.values(['a', 'b', 'c'])
const ar = ['a', 'b', 'c']
Object.values(ar) // simplify to: ar
Pass
['a', 'b', 'c']
const ar = ['a', 'b', 'c']
Object.values(ar)
Additional Info
No response
Josh-Cena
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin