Closed
Description
Code
Maybe we need a convenient way to add assertions on variables which are destructured out.
type StringOrNumber = string | number
const obj = {
foo: 42 as StringOrNumber
}
const { foo } = obj
Nowadays, the workarounds are:
// A:
const { foo } = obj as { foo: number }
// B:
const { foo: foo2 } = obj
const foo = <number>foo2
The first is a burden to rewrite the obj
's type when its type is nested and complicated. The second seems weird.
I'm assuming such a syntax like:
const { <number>foo } = obj
can absolutely help us asserting the type no matter how big the obj
's type is.