Skip to content

Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4 #44281

@xaviergonz

Description

@xaviergonz

Bug Report

Given (this is just the smaller repro I could come up with, not real code):

const p = <T>(fn: () => T): T => {return null as any}

const Base = <T>(val: T): {new(): T} => {
  return null as any;
}

class C extends Base({
 x: p<C[]>(() => [])
}) { }

With TS 4.3.2 it gives the errors:

Type 'C' recursively references itself as a base type.ts(2310)
'C' is referenced directly or indirectly in its own base expression.ts(2506)

where as there's no such error with TS 4.2.4

If the p function parameter is changed from fn: () => T to fn: () => any or x: p<C[]>(() => []) is changed to x: p<C[]>(() => [] as any) then it does not give that error anymore.

Real impact:

This impacts a library that used to be able to do self-referenced models:

class TreeNode extends Model({ children: prop<TreeNode[]>(() => []), x: prop(0) }) {}

but with the new version it is not possible anymore

Alternative repro:

abstract class Base2 {
    abstract root() : Derived
}

class Derived extends class extends Base2 {
  root() {
    return undefined as any
  }
}
{}

🕗 Version & Regression Information

  • This changed between versions 4.2.4 and 4.3.2

⏯ Playground Link

Playground Link

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions