This is working.
JavaScript
x
5
1
let head = [["title", "value"], ["a", 1]];
2
let tail = [["b", 2], ["c", 3]];
3
4
let all = head.concat (tail);
5
The fine result is
JavaScript
1
2
1
[["title", "value"], ["a", 1], ["b", 2], ["c", 3]]
2
But what I need is this – and thats not working.
JavaScript
1
5
1
let head = [["title", "value"]];
2
let tail = [["a", 1], ["b", 2], ["c", 3]];
3
4
let all = head.concat (tail);
5
Error:
JavaScript
1
7
1
Argument of type '(string | number)[][]' is not assignable to parameter
2
of type 'string[] | string[][]'.
3
Type '(string | number)[][]' is not assignable to type 'string[][]'.
4
Type '(string | number)[]' is not assignable to type 'string[]'.
5
Type 'string | number' is not assignable to type 'string'.
6
Type 'number' is not assignable to type 'string'.
7
It works if I make the numbers in tail to strings – what I can not do because of reasons.
So how can I make it work??
Thanks!
Advertisement
Answer
You can declare the type of head
like this:
JavaScript
1
2
1
let head: [Array<string|number>] = [["title", "value"]];
2
This will remove the error and keep the type-safety in place.