Skip to content

Type not matched when using keyof instead of literal #46964

@truemogician

Description

@truemogician

Bug Report

🔎 Search Terms

I've posted this problem on StackOverflow but received no comments or answers.
This problem is rather difficult to describe briefly in natural language (or maybe due to my poor English), thus I failed to find any relative questions through the search engine.

🕗 Version & Regression Information

I'm currently using TypeScript 4.4.4, earlier versions are not tested, but I suppose they'll behave the same.

💻 Code

type a = { foo: "bar" } extends { "foo" } ? true : false;
type b = { [K in keyof { "foo" }]: { foo: "bar" } extends { K } ? true : false }["foo"];

🙁 Actual behavior

a = true
b = false

🙂 Expected behavior

b should also be true

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