Skip to content

Regression: Tagged types are incorrectly refinedΒ #43502

Closed
@arcanis

Description

@arcanis

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions