S
S
Svyatoslav Khusamov2017-04-24 23:28:43
typescript
Svyatoslav Khusamov, 2017-04-24 23:28:43

How to properly describe the type of the rest parameter using array union?

Code example:

function func1(...args: string[] | number[]) {
    //...
}

Error text:
error TS2370: A rest parameter must be of an array type.

I don't need the following code, because my function input will be
either an array of strings or an array of numbers, but not mixed in any way - an array of numbers or strings.
function func1(...args: (string | number)[]) {
    //...
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question