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
Regression: Tagged types are incorrectly refinedΒ #43502
typeHash=string&{__hash: true};functiongetHashLength(hash: Hash): number{// A best effort check in case our function is used by people writing JSif(typeofhash!==`string`)thrownewError(`This doesn't look like a hash`);returnhash.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.
Hmm, yes this is an effect of #43131. The fixes to getTypeFacts are in principle correct, except that here we think that typeof is both "string" and "object", which is impossible and therefore gets us to never. In tagged primitive types like this we should really consider the primitive type be to dominant. I'll put up a PR to that effect.
Activity
arcanis commentedon Apr 2, 2021
An ugly workaround if you don't use Prettier is to do (note the extra parentheses):
ahejlsberg commentedon Apr 5, 2021
Hmm, yes this is an effect of #43131. The fixes to
getTypeFactsare in principle correct, except that here we think thattypeofis both"string"and"object", which is impossible and therefore gets us tonever. In tagged primitive types like this we should really consider the primitive type be to dominant. I'll put up a PR to that effect.