In one of my modules, I use an optional tuple for the function result:
function ruleFromPosition(position): [string, number] | undefined;
and assign this to local vars in my unit tests:
let [ruleName, ruleIndex] = ruleFromPosition(position);
This results in an error:
The type must have a method "Symbol.iterator", which returns an iterator.
I could write this instruction as follows:
let [ruleName, ruleIndex] = ruleFromPosition(position)!;
which compiles, but this prohibits checking with a null value. What is the correct way to use a tuple?
source
share