Skip to content

The type of inference is inaccurate #59361

Closed

Description

🔎 Search Terms

infer unknow

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

// Your code here

🙁 Actual behavior

type MyType<T> = T extends (infer R) & string ? R : never
type Result = MyType<string> // unknown
type MyType<T> = T extends (infer R) & string ? R : never
type Result = MyType<'abc'> // abc

Why is the Result here unknown instead of string? Doesn't infer infer a more precise type? If not, then why is Result abc instead of string when T is abc?

🙂 Expected behavior

type MyType<T> = T extends (infer R) & string ? R : never
type Result = MyType<string> // Expected string

Additional information about the issue

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions