Skip to content

makeDestructurable

类别
导出体积
201 B
上次更改
2 months ago

使对象和数组具有等价的解构性能。详见这篇博文获取更多详情。

用法

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

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
842d7 - fix: fix Typescript < 5.0.0 support (#4028)
4ea13 - feat: support parameters without as const (#3971)