Skip to content

Infer works differently for interface and type alias #63112

@UnVuTWFu

Description

@UnVuTWFu

🔎 Search Terms

infer, index signature

🕗 Version & Regression Information

  • This won't compile.
  • This is the behavior in every version I tried,.

⏯ Playground Link

Playground link with relevant code

💻 Code

interface IntA {
    id: string;
}

type TypeA = {
    id: string
}

type Get<T> = T extends { [index: string]: infer A } ? true : false;
type Res1 = Get<IntA>
// Res1 is false
type Res2 = Get<TypeA>
// Res2 is true

🙁 Actual behavior

When using interface,I cannot get type of A(as example above).But if instead of interface,the infer works.

🙂 Expected behavior

I'd expect the same behaviour in both cases,or I can control pass type or interface.

Additional information about the issue

maybe related #15300

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions