Closed
Description
π Search Terms
discriminant alias condition binding element parameter narrowing narrow
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
type UseQueryResult<T> =
| {
isSuccess: false;
data: undefined;
}
| {
isSuccess: true;
data: T;
};
function useQuery(): UseQueryResult<number> {
return {
isSuccess: false,
data: undefined,
};
}
const { data: data1, isSuccess: isSuccess1 } = useQuery();
function test({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
const { data: data2, isSuccess: isSuccess2 } = useQuery();
const areSuccess = isSuccess1 && isSuccess2;
if (areSuccess) {
data1.toExponential(); // should be ok
data2.toExponential(); // is ok
}
}
π Actual behavior
data1
is not narrowed down
π Expected behavior
data1
should be narrowed down just like data2
is narrowed down
Additional information about the issue
The fix for this would be an extension to the recently landed #56173 . However, it's not straightforward to fix this right now. isConstantReference
can't properly assess if the related parameter symbol is "const" or not and the code operates there on a pseudo reference of the whole binding pattern and not on the individual symbol. It would become much more straightforward if this would land: #56313