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