镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Multiple issues with template literal type narrowing and relations #46125

Closed

Description

🕗 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.

Activity

  1. craigphicks commented on Sep 29, 2021

    @craigphicks

    That was very kind of you to attempt to classify fixed prefixes - and fixed mid?/post-fixes too. I would have thought that classifying fixed prefixes alone would be sufficient.

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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