The order of values in a union affects the correct type inference #59729
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
Union Order Dependence
TS behavior is not supposed to depend on union order, but sometimes does
Milestone
🔎 Search Terms
union order type infer
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about
union
/order
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.5.4#code/C4TwDgpgBAshDO8CGBzaBeKBvKB7MwAlrgHbwD8AXFAEoQDGuATgCYA88wThJKANFACuJANYlcAdxIA+KAF8A3ACgloSFAASSEiwA2EJmwAqszAAoAtgmRpqRgJRR0sgG65CLZUpYNdSJtAAZsL0RKRQ8IIARvD03FEQxlAQAB7AEDrwsNaoENJmSlBFUGBIILq4SCyUhcVFAD7YUFaIuXbyUABkTQAW2noG1Fo6+oYm8rV1jTgtNhDUZo7OUEYd3Th9I4Oa-aPGsnK19tRuHl6RMXGECWZYtbNtUItOsrd4BMRk1DP+IhDA1AA5BZfv9AR05PY+LVNgMmAscPgwmR5EtZHc6pjigB6bFQAB65FqcmhkOUQA
💻 Code
🙁 Actual behavior
options
type isRecord<string, unknown>
🙂 Expected behavior
options
type should be inferred as{ market: string }
Additional information about the issue
if you reverse the order of values in the union:
then the type will be inferred correctly
The text was updated successfully, but these errors were encountered: