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
enumAnimalType{cat='cat',dog='dog'}typeAnimal={type: `${AnimalType.cat}`;meow: string;}|{type: `${AnimalType.dog}`;bark: string;}functioncheck(p: never){thrownewError('Error!')}functionaction(animal: Animal){// Compilesif(animal.type===AnimalType.cat){console.log(animal.meow);}elseif(animal.type===AnimalType.dog){console.log(animal.bark);}else{check(animal)}// Compilesswitch(animal.type){case`${AnimalType.cat}`:
console.log(animal.meow);break;case`${AnimalType.dog}`:
console.log(animal.bark);break;default:
check(animal);}// Does not compileswitch(animal.type){caseAnimalType.cat:
console.log(animal.meow);break;caseAnimalType.dog:
console.log(animal.bark);break;default:
check(animal);// <-- Argument of type 'Animal' is not assignable to parameter of type 'never'}}
π Actual behavior
The last example does not compile
π Expected behavior
To my understanding all three examples do exactly the same and all should compile.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
switch default discriminated Unions
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.3#code/KYOwrgtgBAgiCWECGAbAKgTwA7CgbwCgooBjJAFygF4oByM82gGiKgBMB7Ac2rs69oEAvgQLlsuOIlS9CxcTgBcUAAYASPFOToJAOgZCVAblYRgHAO7KAzuQBO8EFxNCoAH3ysFwZes0JtTBxdfkMTYgAjJDsAaxt7R2dhUQAzMBAScngOEFIAC2ASGIAKLGUQYAA3YDsASk95PLtLKAqLKABRO2a7YtounoBCWlrkgjSMrJyoJEzskGKkANRlLVR6uSgAei2oAGEOCCx4FGBrVngUqEXllF1vaioaNZ1ghg3WYhIc6w5T3RQ3Bu0juZkstXCUFcwBQ1lwl2uSxB9wkj2etyCwBC3A+xC+Pz+WMBXGB2l0UViENY0NhuE2XwKRVJ62pomIO32h2Op3OxGsFng5BIeURtxROFxeLIcNUGhemP0FEMik+UoJ-2JzNB5gsVLxeIidmASBikK+SBlfnlelCKhV+vxIF+GqBSLJFJieodhuNptVbGAKSQYBQ5HtDuFhRKbvWkJErA5ABEOGdWhxKN8jidgKx+YLhaLkd5JeaZda3hRw-rvk7CQDXWKwbqzQajSaW9LJBibdwq2ray6STG7h6vfqfe3-YHg6G+wyo1qIdtdgAeAC0a9gdi4kFAlA4VwetBetCg8GsacoFus8C4ICQEVOUHIHCgWGiSDM5BqUAPz9RtAVNUdiCMQIhCEAA
π» Code
π Actual behavior
The last example does not compile
π Expected behavior
To my understanding all three examples do exactly the same and all should compile.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: