为什么此代码不起作用?
const a = [{ name: 'a', label: 'b' }, { name: 'c', label: 'd' }] as const;
const b = [{ name: 'e', label: 'f' }, { name: 'g', label: 'h' }] as const;
type IArr = typeof a | typeof b;
const fn = (arr: IArr) => arr.filter(el => el.name === 'a');
当我尝试过滤或映射此数组时,Typescript警告: “具有签名,但是这些签名彼此不兼容”
(arr: IArr) => arr.filter(el => {});
但是当我散布这个数组的时候效果很好
(arr: IArr) => [...arr].filter(el => {});