February 2019
Beginner
694 pages
18h 4m
English
Tuples can also use rest syntax, both in function definitions and in object rest and spread. As an example of using tuples and rest in a function definition, consider the following code:
function useTupleAsRest(...args: [number, string, boolean]) {
let [arg1, arg2, arg3] = args;
console.log(`arg1: ${arg1}`);
console.log(`arg2: ${arg2}`);
console.log(`arg3: ${arg3}`);
}
useTupleAsRest(1, "stringValue", false);
Here, we have defined a function named useTupleAsRest, which is using rest syntax, but also defining the args parameter as a tuple. This allows us to destructure the tuple into three variables named arg1, arg2, and arg3 on the first line of this function. We then log all three values to the console. When we call ...
Read now
Unlock full access