TS2677
A type predicate's type must be assignable to its parameter's type. Type 'number' is not assignable to type 'string'.
Broken Code ❌
const isInteger = (input: string): input is number => {
return !!parseInt(input, 10);
};Fixed Code ✔️
The input is declared to be of type string which is why the type predicate cannot turn it into a number because these two declarations are mutually exclusive. That's why we have to declare an input type of any:
const isInteger = (input: any): input is number => {
return !!parseInt(input, 10);
};