繁体   English   中英

打字稿类型中的“三个点”是什么意思?

[英]What does the "three dots" in typescript type mean?

我今天在 Typescript 中遇到了一些问题。

在此处输入图像描述

这种类型中的三个点是什么意思? 我根本找不到任何可以解释这一点的东西。

知道是 Redux 的 combineReducers 函数返回的类型推断

编辑:我编辑了图片,这样我们可以看得更清楚。

EDIT2:我在这里添加代码,我正在尝试做这样的事情

let all: { readonly [key: string]: (...args: any) => any } = {
  form,
  metadatas_reducer,
  loader_reducer
}
const combinedReducer = combineReducers(all)

谢谢你。

这是 TypeScript 扩展运算符: https ://howtodoinjava.com/typescript/spread-operator/

它还可以解构传入的数组和字典,因此您可以通过执行以下操作合并两个字典:

> a = [1,2,3]
[ 1, 2, 3 ]
> b = [4,5,6]
[ 4, 5, 6 ]
> [a,b]
[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
> [...a,...b]
[ 1, 2, 3, 4, 5, 6 ]

VSCode 有时会出于某种原因将类型替换为椭圆,可能是为了缩短它们。 在这种特定情况下,构建输出如下。

export declare const combinedReducer: import("redux").Reducer<import("redux").CombinedState<{
    readonly [x: string]: any;
}>, import("redux").AnyAction>;

这不是扩展运算符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM