Bug Report
π Search Terms
refine regression 4.3 refine never
π Version & Regression Information
Worked with 4.2, stopped working with 4.3 beta
β― Playground Link
https://www.typescriptlang.org/play?ts=4.3.0-dev.20210402#code/C4TwDgpgBAEghgZwBZQLxQcATgSwHYDmUAZFAN4D6FSiSAXFNgK4QC+A3AFCcBmTeAY2A4A9nigEIweMgAyEQsCQAKGsgYykASgZ4mAWwBGELOU5QLUAPRWoAQSjHMUCDx4iswKAKQQBAayh8b0RoESZTPkFhMSCEKCYECAATRxAoSBEwABtoAHdcYUIoACkAZXNLHB4oZVBMmrUUAEJUdAADTFxCdq1Ky0YkLBE8qDwIUYBRLGGsZXaAFSQceOSRCAQ8AHIvbJERQOycf2g4KCbern6oLCkI8SaAOlzFJC5WTiA
π» Code
type Hash = string & {__hash: true};
function getHashLength(hash: Hash): number {
// A best effort check in case our function is used by people writing JS
if (typeof hash !== `string`)
throw new Error(`This doesn't look like a hash`);
return hash.length;
}
π Actual behavior
The hash variable is incorrectly refined to never.
π Expected behavior
The hash variable should remain Hash, since the typeof check is coherent with Hash.
Bug Report
π Search Terms
refine regression 4.3 refine never
π Version & Regression Information
Worked with 4.2, stopped working with 4.3 beta
β― Playground Link
https://www.typescriptlang.org/play?ts=4.3.0-dev.20210402#code/C4TwDgpgBAEghgZwBZQLxQcATgSwHYDmUAZFAN4D6FSiSAXFNgK4QC+A3AFCcBmTeAY2A4A9nigEIweMgAyEQsCQAKGsgYykASgZ4mAWwBGELOU5QLUAPRWoAQSjHMUCDx4iswKAKQQBAayh8b0RoESZTPkFhMSCEKCYECAATRxAoSBEwABtoAHdcYUIoACkAZXNLHB4oZVBMmrUUAEJUdAADTFxCdq1Ky0YkLBE8qDwIUYBRLGGsZXaAFSQceOSRCAQ8AHIvbJERQOycf2g4KCbern6oLCkI8SaAOlzFJC5WTiA
π» Code
π Actual behavior
The
hashvariable is incorrectly refined tonever.π Expected behavior
The
hashvariable should remainHash, since thetypeofcheck is coherent withHash.