Typescript has more trouble resolving circular class references when using mixins / through function invocations #55640
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
🔎 Search Terms
Mixin function invocation circular inherits references itself
Related issues:
#29872
#42383
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.2.2#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oCrgQA8eAfFALxQCGARiqtdlAhAO5QAUAdL9agHMkALhoIQAbQC6ASkrk8AbgCwAKDUAzdAmwBLRFAC21ANYQAsroAeuhCQBC1JNAhXgEBABMksRAyw4+IRE1OKkADRQAGK21AA28MhoAbiknGpQmUbWtlHaeoiinI7OonglEHIU5DEI8Yn+2LhqMkUVAPxlFVU1sQl+yU2oUADeGVmoEMDoqAhcHV1OlfKj41lZAPQbUJ5wUHDAABYQw0e2QlBsukdQFZFnPq7UhmBx0Lo+SLovcboauhBPGt1lBJtNZtkbAg8jpgPoEMUllB2u0uAB5WgAKwgzCcYhAMhkKlU6wAvsTSWo1JgBlBLFCopQjKYLDkEQ4ka53F4fA1BoECJAQmE0hVFs4eqsSTR6GgmMAoJg4k4fPTbFAuR5vLckWNpZkNHA4JxDXBRGqEABBMCvAGeSJcxiiWhGt6hVp0tnW22AqAAHygLrgbrmI1BUxmc0d1CglOlccyYMjnqhalJMip6lUNKSKdsACZGVRjGYLZwOc4NW4tbyBhghoLiKEQKRRUtxctqlLMnQGPLFcqkKq2fmq9ztRVu1laPwTUbzV6bb9AQ63E7A66IO6F1DvcvPP6N8Gt6Hw+Co2uYwnY+MkxCLfm0xms0qVXmrUu7WOa+-C5wLVEnCEqMpJAA
💻 Code
🙁 Actual behavior
The declaration for either
Mixin1F
orMixin2F
(unclear why it's not deterministic) errors with "'Mixin2F' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." and the declaration forMixinApplied
errors with "Type 'MixinApplied' recursively references itself as a base type.(2310)'MixinApplied' is referenced directly or indirectly in its own base expression.(2506)"
I imagine I'm just running into some limits of the TypeScript compiler, but I can come up with at least 3 different scenarios that end with the same final result but without TypeScript errors, and this is preventing perfectly fine Javascript from being written. Mixins and function invocations seem to exacerbate the problem of recursive / circular references in class definitions.
For example, calling
makeMixin
within the function (instead of wrapping the function) and immediately invoking it works (TS playground):Removing the
makeMixin
call also works (TS playground):And of course the non-mixin version works as well (TS playground):
🙂 Expected behavior
It'd be great if the mixin + function invocation example worked as well as the others.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: