Skip to content
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

Interface definition utilizing this type errors out only in specific cases and only when a member is accessed, not before #43613

Open
Danny2462 opened this issue Apr 9, 2021 · 0 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@Danny2462
Copy link

Bug Report

🔎 Search Terms

"interface this"
"interface this" intersection
"is referenced directly or indirectly"
"is referenced directly or indirectly in its own type annotation."
ts(2502)
HKT circular
intersection circular

🕗 Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7

⏯ Playground Link

Playground link with relevant minimal code and commented version

💻 Code

With version 4.2.3

interface foo<T> { a: T; b: this["a"] };
//                       ^- 'b' is referenced directly or indirectly in its own type annotation.ts(2502)
type intersection = foo<string> & foo<number>; // Works in some cases, shown in linked playground
type induces_error = intersection["a"]; // Comment this out and the error in the interface goes away

Found when messing with ways to simulate HKTs with this type, which itself seems to be considered a valid use case, per:
#40928 #40967

🙁 Actual behavior

  • Interface definition erroring out for an unclear reason when using said interface later down the line, but not before. It doesn't seem right that the definition shows an error that wasn't there before by just accessing a property.
  • Error itself is questionable, worked in 3.8.3, and a similar use case seems to be covered by the test (Test indexed access to this on intersections #40967) linked above?

🙂 Expected behavior

  • Interface definition either always errors, or an error doesn't pop up only when using the interface definition only in specific ways.
  • Additionally, reason for circularity error is not immediately obvious to me, and it seems it might a regression since 3.8.3?
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Apr 9, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Apr 9, 2021
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

No branches or pull requests

2 participants