Skip to content

Circularity error in intersection of object with index signature #38672

Closed

Description

TypeScript Version: 4.0.0-dev

Code

type Foo1 = { x: string } & { [x: number]: Foo1 };    // Circularity error
type Foo2 = { x: string } & { [K in number]: Foo2 };  // No error

Expected behavior:

No errors.

Actual behavior:

Error: Type alias 'Foo1' circularly references itself.

Playground Link:

https://www.typescriptlang.org/play/index.html?ssl=1&ssc=1&pln=3&pc=1#code/C4TwDgpgBAYg9nAjFAvFA3lAHgLigZ2ACcBLAOwHMoBfKAMgygG1coyBXAWwCMIiBdPPCQ0A3FAlQA9FKgBhEkQDG7ADYBDUqCh8icIgChQkWAgBMqRq0KlKNeoyYBpKOTZdeAoebESZUADk4HSI9QyA

Activity

  1. ahejlsberg commented on May 20, 2020

    @ahejlsberg
    MemberAuthor

    Noticed this as I was writing some code. Issue is we check for empty object types in intersections, which currently causes resolution of object type members, which in turn causes unexpected circularities when the types have index signatures. We need to revise the empty object type check to not require member resolution (which really isn't necessary).

  2. DanielRosenwasser commented on May 20, 2020

    @DanielRosenwasser
    Member

    Brian Terlson (@bterlson) I think you ran into some weird code that wasn't working here. Check out the packed playground when it's ready over at #38673 (comment)

  3. DanielRosenwasser commented on May 20, 2020

    @DanielRosenwasser
    Member

    Glad this was a bug, others on the team were telling me this behavior was expected which made no sense because...well, it was a big feature in 3.7!

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

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions