type Plan<T> = [T[], ...T[]];
I declared a type named Plan, which includes a repetitive plan in index 0 and in the rest what to execute initially.
example) const life: Plan<string> = [ ["getUp", "work", "sleep"], "birth", "grow" ]
And I tried to define the following function:
function parsePlan<T>(plan: Plan<T>, index: number): T {
if(index < 1) throw Error();
return index < plan.length
?plan[index]
:plan[0][(index-plan.length)%(plan[0].length)]
}
but It says there is a problem that this would return T | T[].
If index < 1 it will throw Error() and that makes it impossible to return T[].
Why does this error appear, and how can I fix this error?
Thanks a lot for your help.