For the following code
❌ let b:({[key:string]:string} & {test:number})[] = [{yes:"yes", test:3}];
Why does the definition b show an error?
Type '{ yes: string; test: number; }' is not assignable to type '{ [key: string]: string; } & { test: number; }'.
Type '{ yes: string; test: number; }' is not assignable to type '{ [key: string]: string; }'.
Property 'test' is incompatible with index signature.
Type 'number' is not assignable to type 'string'.ts(2322)
>Solution :
Replacing & with | fixes the issue for me
let a:{[key:string]:string} | {test:number} = {yes:"yes", test:3};
let b:({[key:string]:string} | {test:number})[] = [{yes:"yes", test:3}];
& takes the common part of the two types, but there is no common part of {[key:string]:string} and {test:number}