You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optional discriminated union's callback parameter type is not inferred #35769
typeT1={as?: 'button',onClick?: (el: number)=>void}typeT2={as: 'a',onClick?: (el: string)=>void}typeT=T1|T2;// onClick first parameter type is inferred according to T1 (number)constmyT1_1: T={as: undefined,onClick: _ev=>{}}// onClick first parameter type is inferred according to T1 (number)constmyT1_2: T={as: 'button',onClick: _ev=>{}}// onClick first parameter type is inferred according to T2 (string)constmyT2_1: T={as: 'a',onClick: _ev=>{}}// onClick first parameter type is not inferred (any)constmyT1_3: T={onClick: _ev=>{}}
Expected behavior:
onClick _ev parameter of myT1_3 is inferred to be a number
Actual behavior:
onClick _ev parameter of myT1_3 is any
Activity
wvanvugt-speedline commentedon Feb 5, 2021
This appears to be a duplicate of #41759
IanVS commentedon Jun 4, 2021
The parameter seems to be correctly inferred in the latest version of typescript, can this be closed as fixed?
RyanCavanaugh commentedon Jun 11, 2021
Confirmed fixed 4.2 -> 4.3
wzono commentedon Nov 18, 2021
Ryan Cavanaugh (@RyanCavanaugh) Still exist in the last version..
https://www.typescriptlang.org/play?ts=4.5.0-beta#code/C4TwDgpgBAglC8UDeAoK6qkgfgFxQHIYCAaNDAQ3wAoBjfJKAE3wDsBXAWwCMIAnKAF8AlAgB8UAG4B7AJZMA3CkEoUWaACEEycunX4CG0rqhUodBszZdefElHpQAzsD6zWAcyGj4EmfKUVVXVYDQBhbTgAHygtJRRJCgEzGHCAbQBdKBiAJQhaaT4mAB4XN097VLDMiUQ0k1QMJtMaMCSKTicfCUbmvpMmlUGUDKA