How to fix Type 'X | Y' is not assignable to type 'Z' in TypeScript | DevErrors