Closed
Description
Bug Report
π Search Terms
instanceOf
predicate
π Version & Regression Information
- This error is appearing to me in versions 4.9.4, 4.8.2 & 4.4.4. Nothing makes me think it worked before in prior versions.
β― Playground Link
π» Code
const foo = () => {
const a = 5
const b = new Error('b')
const c = new Error('c')
const d = 'Hello world'
const ls = [a, b, c, d]
ls.filter<Error>(curr => curr instanceof Error)
// Result: (2)Β [Error: b, Error: c]
// Throws error:
// Argument of type '(curr: string | number | Error) => boolean' is not assignable to parameter of type '(value: string | number | Error, index: number, array: (string | number | Error)[]) => value is Error'.
// Signature '(curr: string | number | Error): boolean' must be a type predicate.ts(2345)
}
π Actual behavior
It is neither recognizing the predicate function nor that the result will be an array of Error
values.
π Expected behavior
Interprets that the function is a predicate and filter the errors with the operator instanceOf
.