При использовании MyInterfaceOne[] | MyInterfaceTwo[]
я получаю ошибку Typescript в другом месте моего кода, которая не имеет смысла для меня.
myInterfaces = funcWithAboveSignature()
return myInterfaces.reduce(async (acc, interfaceType) => {
await acc;
if (interfaceType.prop) {
return await someAsyncFunc(interfaceType);
} else {
return await someOtherAsyncFunc(interfaceType);
}
}, Promise.resolve());
Ошибка говорит:
Argument of type '(acc: MyInterfaceOne, raw: MyInterfaceOne) => Promise<void>' is not assignable to parameter of type '(previousValue: MyInterfaceOne, currentValue: MyInterfaceOne, currentIndex: number, array: MyInterfaceOne[]) => MyInterfaceOne'.
Но при изменении сигнатуры функции с MyInterfaceOne[] | MyInterfaceTwo[]
на (MyInterfaceOne|MyInterfaceTwo)[]
она работает.
Может кто-нибудь объяснить мне разницу между этими двумя?