-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels