Type inference fails when using combined boolean variable in if condition #55577
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
🔎 Search Terms
"typescript destructuring losses types", "typescript destructuring losses type object is possibly undefined", "typescript type alias destructuring loses type", "typescript inference with union types"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAqgzhAigVwgJxAJQnZAbYAHgBUA+KAXigG8AoKBqASzgGVkBjDnOALigBmAQzwIA3PUYATIcCH9kAOykQBTRRCkSAvlAA+NSQxbsuPfsDSoJjKDLn9itbRNoClHYEwD2iqMgQUdBAACgBKfngkVAxsXAJCRWQAWwAjdHI6WzQIYGQ0PyzbRhNObjg+QREEABojYvt5f2VVdU062xdnWloOXzhgGjtZJsaARhrmNjLzKdNyuDGoXSoA6ODwiT7FAaHG-kaAJknSswr+U4XD5cp-QJjQsK3+wephh3ehAGYT6bPKy48L43Vb3DZPHoAekhUAAkoMAO7eNAAazgUCE6IgAA9IJ5NLQmAIoCFARUlgAyClzGYVa5Umn-L5hQy2cYAOmA3gAorjfBBFF4RJt6kdOTy+RpBUxhRC2SMvuLeWB+dLZToettdkIcvMeLcyYsoAzDfTqYavq5oXDBlJvDhFAByRHIlFQAAW6AgkwR7qYeGgTGAjvRACsAoMhFA+ml1LIfH5vMSQ7SEHBHYTiSEdRA9RUWUUGByucrVUK8CL5XJDkrJQLy5XpArayqpQ2IdogA
💻 Code
🙁 Actual behavior
The issue occurs when using the combined boolean variable
areSuccess
in the second if condition. AlthoughisSuccess1
,isSuccess2
, andisSuccess3
are all true, TypeScript cannot narrow down the types ofdata1
,data2
, anddata3
within the if block, leading to a type error🙂 Expected behavior
areSuccess
is a combination of the individualisSuccess
variables, it should correctly infer the types ofdata1
,data2
, anddata3
as the specific data type (number) defined for the queries. This should allow the code to call the toExponential method on each data variable without any issues.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: