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
// Welcome to the TypeScript Playground, this is a website// which gives you a chance to write, share and learn TypeScript.// You could think of it in three ways://typeA={a: string}typeB=A&{b: string;}constisB=(a: A): a is B=>typeof(aasany).b==="string"constwithUnreachable=(a: A)=>{if(true)return;console.log("hello world")if(isB(a))console.log(a.b)}constwithoutUnreachable=(a: A)=>{console.log("hello world")if(isB(a))console.log(a.b)}
π Actual behavior
type error is thrown because the type guard is not executed
π Expected behavior
type guards should be processed even if the code is unreachable, or all type checking should be disable for unreachable code
Additional information about the issue
I tested with all versions available on the playground, none work. Full type checking is not executed on unreachable code even when allowUnreachableCode is true. It seems that the type guards do not infer the guarded type if it is in an unreachable block, so I get a compile error. This isn't a huge deal but during testing sometimes it's easier to force an early return.
The text was updated successfully, but these errors were encountered:
π Search Terms
type guard unreachable code allowUnreachableCode
π Version & Regression Information
Version 5.3.3
β― Playground Link
https://www.typescriptlang.org/play?allowUnreachableCode=true&ts=5.4.0-dev.20240215#code/PTAEHUFMBsGMHsC2lQBd5oBYoCoE8AHSAZVgCcBLA1UABWgEM8BzM+AVwDsATAGiwoBnUENANQAd0gAjQRVSQAUCEmYKsTKGYUAbpGF4OY0BoadYKdJMoL+gzAzIoz3UNEiPOofEVKVqAHSKymAAmkYI7NCuqGqcANag8ABmIjQUXrFOKBJMggBcIYqohCgAgqAAvKAA3oqgDWL5oIKolJzMigC+wSVEoABCVaAVAGS19Y3Sza3tzADc3cEInK0igkPVABQMzWUAlM3iopsAfGilKaA7YsJmePsB0lWV1QBEsxnMb8vwqzQSeSYACqnCcDFM0ncwx2e32VVOijqjREqS2bXYkHhTlQ7DInEWkwaK0E8HcAWg8GYWze2GglMk8DI0Te+2CKIoaKEAx2+zZKJRJLJkApVJ2TzZPUUJIBQI4qFB4Mh0O2uxG8MqiORjSF5Mp1NpMAZEiZLLZRNR125vP5AuJf1JerFDAlSwaQA
π» Code
π Actual behavior
type error is thrown because the type guard is not executed
π Expected behavior
type guards should be processed even if the code is unreachable, or all type checking should be disable for unreachable code
Additional information about the issue
I tested with all versions available on the playground, none work. Full type checking is not executed on unreachable code even when
allowUnreachableCode
istrue
. It seems that the type guards do not infer the guarded type if it is in an unreachable block, so I get a compile error. This isn't a huge deal but during testing sometimes it's easier to force an early return.The text was updated successfully, but these errors were encountered: