Back to Vueuse

makeDestructurable

skills/vueuse-functions/references/makeDestructurable.md

14.3.0698 B
Original Source

makeDestructurable

Make isomorphic destructurable for object and array at the same time. See this blog for more details.

Usage

TypeScript Example:

ts
import { makeDestructurable } from '@vueuse/core'

const foo = { name: 'foo' }
const bar = 1024

const obj = makeDestructurable(
  { foo, bar } as const,
  [foo, bar] as const,
)

Usage:

ts
// @include: main
// ---cut---
let { foo, bar } = obj
let [foo, bar] = obj

Type Declarations

ts
export declare function makeDestructurable<
  T extends Record<string, unknown>,
  A extends readonly any[],
>(obj: T, arr: A): T & A