Skip to content

Multiple issues with template literal type narrowing and relationsΒ #46125

Closed
@ahejlsberg

Description

@ahejlsberg

πŸ•— Version & Regression Information

Every version.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function f1(x: `foo-${string}`, y: `${string}-bar`) {
    if (x === y) {  // Wrongly reports error that types don't overlap (they do, e.g. 'foo-xxx-bar')
    }
}

function f2(x: string, y: `foo-${string}` | 'bar') {
    if (x === y) {
        x;  // Narrowed to 'bar', should be `foo-${string}` | 'bar'
    }
}

function f3(x: string, y: `foo-${string}`) {
    if (x === 'foo-test') {
        x;  // Narrowed to 'foo-test'
    }
    if (y === 'foo-test') {
        y;  // Not narrowed but should be
    }
}

πŸ™ Actual behavior

See above.

πŸ™‚ Expected behavior

See above.

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