[Feature Request] Type guard on conditional types #23493
Closed
Description
Code
type Test<V, M extends boolean> = { multiple?: M } & (
M extends true ? { values: V[] } : { value: V }
)
function typeGuard<V, M extends boolean>(input: Test<V, M>) {
if (input.multiple) {
return input.values;
} else {
return input.value;
}
}
Expected behavior:
input.values
can be inferred in if
block and input.value
can be inferred in else
block.
Actual behavior:
Property 'values' does not exist on type 'Test<V, M>'.
Property 'value' does not exist on type 'Test<V, M>'.
Related Issues: