Skip to content

5.6 regression: Inference with mixed in type intersection no longer compilesΒ #59765

Closed as not planned

Description

πŸ”Ž Search Terms

Inference

πŸ•— Version & Regression Information

  • This changed between versions 5.5.4 and 5.6.0-beta (still happening in 5.6.1-rc)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.1-rc#code/C4TwDgpgBAYgrgOwMbAJYHsEGF0FsyYQLAA8AClALxQCGCIAfFVABRgBO6YAzgFxRkAlFSYBRADYRcRYFAA+UBHHHiA3ACh1qYhHYAzGkmgSpMgILBg7VACM4wCNygBvdVCioAJngDSEEAD8-NxW2gDm8orK4pFKuDa6Gu5IABao4p7sREFQiADWCOgA7ghJUNx5qGA5NujoknQaAL6anhBI4jRZUHqIKBgIUBCS0sTkDCxuUMA0YfzwyGiYOPiEYxQAZFAmo8AWoXYO3AwANFM0ltaHjvyb2yPml7b2jmeC-DsyGuptHV3QvUWA3uADkaNI2JwePxnAhwRAciFrAgwk13vdTMRvsNMcAWBIwdITi40RoAPRkqAAEXQjkU6FkSDwYHS0G0UAArAA6ABsXKgAGUUuhlJ4oEz8KyueogA

πŸ’» Code

type FunctionComponent<P = any> = (props: P) => Element | null;

interface ElementAttributes {
  idomKey?: string | null | number;
  children?: unknown;
  skip?: boolean;
}

declare function element<P>(
  tag: FunctionComponent<P & ElementAttributes>,
  attributes: P & ElementAttributes,
): Element;

declare function ElName(props: {name?: string}): Element;

element(ElName, {});
// Does not compile in 5.6. Should compile.

πŸ™ Actual behavior

Last line errors with:

Argument of type '(props: { name?: string | undefined; }) => Element' is not assignable to parameter of type 'FunctionComponent<ElementAttributes>'.
  Types of parameters 'props' and 'props' are incompatible.
    Type 'ElementAttributes' has no properties in common with type '{ name?: string | undefined; }'.(2345)

πŸ™‚ Expected behavior

Compiles as it did in previous versions

Additional information about the issue

Confirmed that #59709 does not resolve this issue.

(Google note: relevant source location http://shortn/_Ce1E5yV592)

Activity

  1. RyanCavanaugh commented on Aug 27, 2024

    @RyanCavanaugh
    Member
  2. Andarist commented on Aug 27, 2024

    @Andarist
    Contributor

    This one is not beyond repair πŸ˜‰ #59772

  3. changed the title [-]Inference with mixed in type intersection no longer compiles[/-] [+]5.6 regression: Inference with mixed in type intersection no longer compiles[/+] on Aug 27, 2024
  4. RyanCavanaugh commented on Aug 30, 2024

    @RyanCavanaugh
    Member

    There are definitely going to be multiple correct possible inferences when all sites for a type parameter are the nested in the same intersection, and a "smaller" inference for P seems justifiable from the principle of being most likely to be sound in practice.

    It seems like the "right" fix here is to change element to use a constraint instead:

    declare function element<P extends ElementAttributes>(
      tag: FunctionComponent<P>,
      attributes: P,
    ): Element;

    which works as expected.

  5. typescript-bot commented on Sep 2, 2024

    @typescript-bot
    Contributor

    This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis 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