Skip to content

Type containing templated, branded string is not assignable to itselfΒ #61098

Closed
@HansBrende

Description

@HansBrende

πŸ”Ž Search Terms

brand branded tag tagged template string not assignable extends different type name unrelated

πŸ•— Version & Regression Information

  • This changed between versions 5.0.4 and 5.1.6

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/FAUwHgDg9gTgLgAgDYkQQwFwIBQB4AqAfNgJQIC8hC+C4cIAdgCYDOCABgCQDeA5GrwQAyBNwSYEARgQBfGewQB+KQiwAmMuQQMArkiQBCANyhIsRCkQAjLHiKkKVGnUasOPfoJFiJ0uQuVpdU1tPUMTYDQKBCsjIA

πŸ’» Code

export let a: (<T>() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!;
export let b: (<T>() => T extends `${'a' & { a: 1 }}` ? 1 : 2) = null!;

a = b; // ❌ Error!

πŸ™ Actual behavior

Typescript error:

Type
'<T>() => T extends `${"a" & { a: 1; }}` ? 1 : 2' is not assignable to type
'<T>() => T extends `${"a" & { a: 1; }}` ? 1 : 2'.
Two different types with this name exist, but they are unrelated.

πŸ™‚ Expected behavior

No error

Additional information about the issue

I would expect that, as a general principle, any type which is copy-and-pasted from one place to another should be assignable to itself. (With the exception of unique symbol, since by design it's supposed to not do what I just said.) This is perhaps the most lax notion of assignability that could possibly exist, I would think.

Note that, as soon as I remove either the outer template or the inner brand, assignability works as expected once again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions