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
typeEasing='ease-in'|'ease-out'|'ease-in-out';functiongetEasingFunction(easing: Easing): (val: number)=>number{switch(easing){case'ease-in': returnt=>t*t;case'ease-out': returnt=>t*(2-t);case'ease-in-out': returnt=>t<0.5 ? (2*t*t) : -1+(4-2*t)*t;}// `easing` should be of type `never` here// however the actual type is `'ease-in' | 'ease-out' | 'ease-in-out'`}
Expected behavior:
After an exhaustive switch the switched variable should be of type never as per #9163. Conversely, if the switch is not exhaustive and the return type does not accomodate for undefined, an error should be issued.
Actual behavior:
String literal union types are not narrowed thus an error is always issued.
typeEasing={val: 'ease-in'}|{val: 'ease-out'}|{val: 'ease-in-out'};functiongetEasingFunction(easing: Easing): (val: number)=>number{switch(easing.val){case'ease-in': returnt=>t*t;case'ease-out': returnt=>t*(2-t);case'ease-in-out': returnt=>t<0.5 ? (2*t*t) : -1+(4-2*t)*t;}// `easing` should be of type `never` here// however the actual type is `'ease-in' | 'ease-out' | 'ease-in-out'`}
Activity
gcnew commentedon Jun 22, 2016
PS: Kudos for #9163 and all the work you've put in TS. It's a trully amazing language.
aluanhaddad commentedon Jun 22, 2016
Marin Marinov (@gcnew) interestingly, this works:
gcnew commentedon Jun 22, 2016
Aluan Haddad (@aluanhaddad) Yeah, another workaround that doesn't change
Easingalias:ahejlsberg commentedon Jun 22, 2016
This is a duplicate of #7447.