Skip to content

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

Closed

Description

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.

Activity

  1. canonic-epicure commented on May 27, 2021

    @canonic-epicure

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

  2. dsherret commented on May 27, 2021

    @dsherret
    ContributorAuthor

    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.

  3. xaviergonz commented on May 28, 2021

    @xaviergonz

    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

  4. dsherret commented on May 29, 2021

    @dsherret
    ContributorAuthor

    Javier Gonzalez (@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.

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

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions