Skip to content

Circularity error in intersection of object with index signature #38672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahejlsberg opened this issue May 20, 2020 · 3 comments · Fixed by #38673
Closed

Circularity error in intersection of object with index signature #38672

ahejlsberg opened this issue May 20, 2020 · 3 comments · Fixed by #38673
Assignees
Labels
Bug A bug in TypeScript

Comments

@ahejlsberg
Copy link
Member

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

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label May 20, 2020
@ahejlsberg ahejlsberg self-assigned this May 20, 2020
@ahejlsberg ahejlsberg added this to the TypeScript 4.0 milestone May 20, 2020
@ahejlsberg
Copy link
Member Author

ahejlsberg commented May 20, 2020

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).

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented May 20, 2020

@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)

@DanielRosenwasser
Copy link
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants