跳到主要内容

makeDestructurable

分类
导出大小
201 B
上次更改
3 个月前

使对象和数组同时具有同构解构能力。更多详情请参阅这篇博客

用法

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

类型声明

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

来源

源代码文档

贡献者

Anthony Fu
SerKo
Breno A
enpitsulin

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
842d7 - 修复: 修复 TypeScript < 5.0.0 支持 (#4028)
4ea13 - 特性: 支持没有 as const 的参数 (#3971)

根据 MIT 许可证发布。