Closed
Description
Bug Report
π Search Terms
- type guard
- inference
- if condition
π Version & Regression Information
This is a regression.
Inference was OK on 4.7.4
but broken on 4.8.4
and 4.9.5
(tested on the playground).
β― Playground Link
Playground link with relevant code
π» Code
export type Writable<T> = {
-readonly [K in keyof T]: T[K];
};
class Foo {
readonly foo = 'foo';
}
class Bar {
readonly bar = 'bar';
}
type WritableFooBar = Writable<Foo | Bar>;
declare function isFoo(obj: any): obj is Foo;
function test(foobar: WritableFooBar): void {
if (!isFoo(foobar)) {} // happens also with if(isFoo())
foobar
// ^? Foo | Writable<Bar>
}
π Actual behavior
foobar
is inference as Foo | Writable<Bar>
π Expected behavior
foobar
should be inferred as Writable<Foo|Bar>
or WritableFooBar
Metadata
Metadata
Assignees
Labels
No labels