Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@xaviergonz

Description

@xaviergonz
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.