I have an interface that accepts { [key:string]: string }.
I want to test several cases for it. For this I want to define an array containing my test cases as follows:
const tests: [ {[key: string]: string} ] = [{
"A": "B"
}, {
"C": "D"
}]
But it will not compile because Typescript is assuming those inline objects are types in of themselves.
Type '[{ A: string; }, { C: string; }]' is not assignable to type '[{ [key: string]: string; }]'. Source has 2 element(s) but target allows only 1.
{[key: string]: string}[]Array<{[key: string]: string}>should also work. The problem is that your declaration only allows one element inside of the array, yet you pass 2 elements into it.