John John - 1 year ago 99
TypeScript Question

what is the ... syntax in typescript

Jumping from regular old js with ang1 to ang2 with typescript and redux etc is a heck of a steep climb.

Could anyone offer a simple explanation to the ... syntax? Having come from a php and javascript background this is really new stuff. shows this as an example with redux:

return {
messages: [
...state.messages.slice(0, idx),
...state.messages.slice(idx + 1, state.messages.length)

But does anyone have an uber simple example for a complete noob to this area? Feels like i'm going round in circles!

Answer Source

The three dots represent the rest operator and it is used to get the arguments list passed to function on invocation and in array destructure. A case when the operator gathers the rest remained after the operation.

The spread operator is used for array construction and destructuring, and to fill function arguments from an array on invocation. A case when the operator spreads the array (or iterable object) elements.

You can read more about this here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download