How to fix Type 'T extends U ? X : Y' is not assignable to type 'Z' in TypeScript | DevErrors