コンテンツへスキップ

makeDestructurable

カテゴリ
エクスポートサイズ
364 B
最終更新
6ヶ月前

オブジェクトと配列に対して同時に同型に分割可能な構造を作成します。詳細については、このブログを参照してください。

使い方

TypeScriptの例

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

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

const obj = makeDestructurable(
  { foo, bar } as const,
  [foo, bar] as const,
)
js
import { makeDestructurable } from '@vueuse/core'
const foo = { name: 'foo' }
const bar = 1024
const obj = makeDestructurable({ foo, bar }, [foo, bar])

使い方

ts
let { foo, bar } = obj
let [foo, bar] = obj

型定義

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

ソース

ソースドキュメント

貢献者

Anthony Fu
Breno A
enpitsulin

変更履歴

v10.10.1 2024/6/11
842d7 - fix: Typescript < 5.0.0 のサポートを修正(#4028)
v10.10.0 2024/5/27
4ea13 - feat: as constなしのパラメータをサポート(#3971)

MITライセンスの下でリリースされています。