refactor, object destruction
A refactor that extract all property access expression to a object destruction or convert back

const item = {
a: 1, b: 2
}
call(item.a, item.b)
to
const item = {
a: 1, b: 2
}
const { a, b } = item
call(a, b)
My suggestion meets these guidelines:
This doesn't deserve an example of what it would do?
Updated
@Kingwl While this does sound nice in theory I believe there would issues around unions. Type gurads work differently on union types so not everything that can be done with a union could be done with the distructured constituents. For example:
let u!: { type: 'number'; payload: number } | { type: 'string', payload: string }
if(u.type === "number") {
u.payload.toExponential // payload is number
} else {
u.payload.big // payload is string
}
let { type, payload } = u
if(type === "number") {
payload.toExponential // error payload is string | number
} else {
payload.big // error payload is string | number
}
This is not a reason not to implement this, but great care should be taken not to offer this refactoring when resulting code would break because of type guards.
I鈥榤 very interested in this one if we accept the pr
any updates on this feature?
@wimzyLive no
I start working on this one :XD
It seems to be a duplicate of #25946
@bigaru
Indeed. Thanks!
Most helpful comment
@Kingwl While this does sound nice in theory I believe there would issues around unions. Type gurads work differently on union types so not everything that can be done with a union could be done with the distructured constituents. For example:
This is not a reason not to implement this, but great care should be taken not to offer this refactoring when resulting code would break because of type guards.