How to fix Cannot infer type variable 'T' in conditional type in TypeScript | DevErrors