Suppose that you have the following types:
type Foo = {
value: string | number
}
type Extra<F> = F extends Foo
? F['value'] extends number
? F & {extra: number}
: F & {extra: boolean}
: F
and the next piece of code:
const isExtra = (f: Foo): f is Extra<Foo> => 'extra' in f
const process = <T extends Foo>(item: T) => {
if (isExtra(item)) {
if (typeof item.value === 'number') {
const result = item.extra // boolean !!!
}
}
}
const result
is resolving to boolean while it should resolve to number (according to types). What is wrong?
Playground