Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "three dots" mean in TypeScript?

I stumped on something in Typescript today.

enter image description here

What does the three dots mean in this type?

I can't find anything that explain this at all.

I'm trying to do something like this

let all: { readonly [key: string]: (...args: any) => any } = {
  form,
  metadatas_reducer,
  loader_reducer
}
const combinedReducer = combineReducers(all)
like image 497
Quoc-Hao Tran Avatar asked Nov 17 '25 22:11

Quoc-Hao Tran


2 Answers

This is the TypeScript spread operator: https://howtodoinjava.com/typescript/spread-operator/

Which can also destructure incoming arrays and dictionaries, so you can merge two dictionaries by doing this:

> 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 ]
like image 179
Chris Avatar answered Nov 19 '25 13:11

Chris


VSCode will sometimes replace types with an ellipse for some reason, possibly to shorten them. In this specific case, the build output is the following.

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

This is not the spread operator.

like image 38
Trevor Karjanis Avatar answered Nov 19 '25 13:11

Trevor Karjanis