Closed as duplicate
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