How to fix Conditional type branch produces a union type that is too complex to represent in TypeScript | DevErrors