Typescript type inference not working as expected I have two very similar functions but typescript can infer the return value of only one of them: