Skip to content

Mixin base requires explicit type in TS 4.3 due to "recursively referencing itself" when it doesn't #44284

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
dsherret opened this issue May 27, 2021 · 4 comments

Comments

@dsherret
Copy link
Contributor

dsherret commented May 27, 2021

Bug Report

I'm having a scenario in TS 4.3 where the compiler can no longer figure out the base mixin type implicitly. It seems like a bug to me, but maybe not.

Setup

Here's the starting mixin code with an initial error I get unrelated to this issue I'm reporting (it started happening in TS 3.x something):

image

I'm not sure what is going on with the error, but I can get around it by doing some indirection or extracting it out to another variable declaration (shown in next image below). This now shows the error I'm reporting here that started happening in TS 4.3 where it says that the type ModuleDeclaration recursively references itself as a base type. It doesn't give any details about where this occurs, so if anything an improvement to that error saying exactly why might be nice.

image

Workaround (Explicit Type)

Workaround is to explicitly type the base type:

image

🔎 Search Terms

mixin, recursive

This seems related to #42383, but different in that it only started occuring in TS 4.3.

🕗 Version & Regression Information

  • This changed between versions 4.2.4 and 4.3
  • Occurs in 4.4.0-dev.20210526

⏯ Playground Link

Can't figure out a smaller reproduction.

💻 Code

Can't figure out a simple reproduction for this one, but the compile error can be reproduced by following these steps:

  1. Check out the commit for this change in ts-morph: dsherret/ts-morph@6c74e26
  2. Run yarn setup in the root (sorry, it's slow right now).
  3. Modify ModuleDeclarationBase in packages/ts-morph/src/compiler/ast/module/ModuleDeclaration.ts to no longer have an explicit type.
  4. Run yarn build in packages/ts-morph or look at error in VS code via the language service.

🙁 Actual behavior

Error stating Type 'ModuleDeclaration' recursively references itself as a base type.

🙂 Expected behavior

No error.

@canonic-epicure
Copy link

As another mixins user, I believe this issue is quite important. If this is a regression in 4.3, then the internal TypeScript test coverage for mixins is not complete yet. Perhaps try to reduce the reproducible case to a bare minimum, I doubt TS team will dig into this themselves..

@dsherret
Copy link
Contributor Author

Oh, looks like this might be a duplicate of #44281, which was logged before this. (Didn't find it while searching because that issue didn't mention mixins)

I will investigate more later.

@xaviergonz
Copy link

xaviergonz commented May 28, 2021

Could you check if the error happens with 4.3.0-dev.20210428 but does not happen in 4.3.0-dev.20210427?
If so then most probably it is the same bug for sure

@dsherret
Copy link
Contributor Author

@xaviergonz yup, it worked in 4.3.0-dev.20210427, but not 4.3.0-dev.20210428. I'm going to close this one in favour of #44281.

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

No branches or pull requests

3 participants