Answer the question
In order to leave comments, you need to log in
How to type the input parameters of a function, which can change during the check?
there is some function that can take an object or an array of these objects.
on initial argument check, if not an array wraps the object in an array.
ts swears at the whole thing.
Whether probably this business to make friends without the declaration of a new variable?
fn(x: any, y: any, z: any):any{
if (!Array.isArray(x)) x = [x];
if (!Array.isArray(y)) y = [y];
if (!Array.isArray(z)) z = [z];
// .....
}
Answer the question
In order to leave comments, you need to log in
For example:
function fn(x: number | Array<number>): void {
if(!Array.isArray(x))
x = [x];
console.log(x);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question