Skip to content

Distributive type on generic has surprising resultsΒ #61169

Closed
@ceymard

Description

@ceymard

πŸ”Ž Search Terms

remove generic string type from union containing it with string literals / filter generic string out of union containing literal types

πŸ•— Version & Regression Information

5.7

⏯ Playground Link

No response

πŸ’» Code

type LiteralString<T> = string extends T ? never : T;

type Test1 = LiteralString<string>; // never
type Test2 = LiteralString<"literal">; // "literal"
type Test3 = LiteralString<string | "literal"> // shoud be "literal"

πŸ™ Actual behavior

Test3 ends up being never

πŸ™‚ Expected behavior

Test3 should be "literal"

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions