Closed
Description
This code will not compile:
function isString1(a: number, b: Object): b is string {
return typeof b === 'string'
}
function isString2(a: Object): a is string {
return isString1(0, a)
}
Output:
foo.ts(6,9): error TS1226: Type predicate 'b is string' is not assignable to 'a is string'.
Parameter 'b' is not in the same position as parameter 'a'.
The code will work if I swap the parameters of isString1
so that the predicated parameter for both functions is the first argument.
Is there a good reason that this is required?