There is no currently syntax for something like that: you have to be explicit. Even for import
syntax doesn't exists something like that, that would import all the "keys" (exported value) in the scope without being explicit (declaring which "keys" import, or assign the whole module to an object).
If you need most of the keys of an object, probably the best way it would be just use the object directly (o.test1
) without destructuring.
Of course in case you have access to the current scope object, such as globalThis
, you can always doing something like:
Object.entries(o).forEach(([key, value]) => globalThis[key] = value)
But first, it will work only if you're assign the object value to the global object (so no local scope); and second I don't see how it's different writing this code and then using test1
instead of avoid such code and write o.test1
.
(And, of course it's something really horrible to write that you shouldn't never do it, I added just for completition).