Closed
Description
Bug Report
π Search Terms
type narrowing based on function typeof is broken when intersection with a record is used
π Version & Regression Information
- Recent change in behaviour happened in version 4.3.5
β― Playground Link
Playground link with relevant code
π» Code
type Meta = { foo: string }
interface F { (): string}
const x = (a: (F & Meta) | string) => {
if (typeof a === "function"){
// ts.version >= 4.3.5: never -- unexpected
// ts.version <= 4.2.3: F & Meta -- expected
a;
} else {
// expected: string
// ts.version >= 4.3.5: string -- expected
// ts.version <= 4.2.3: string | (F & Meta) -- unexpected
a;
}
}
π Actual behavior
behavior was half correct from in TS versions <= 4.2.3, but then it was changed in 4.3.5 which fixed the part that was wrong previously, but broke the other part that was correct. So we still have half broken behavior.
π Expected behavior
It's expected to pick the correct parts from the both versions.