TypeScript: Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 20 (3 by maintainers)
Commits related to this issue
- Lock and update deps to fix build memory leak - I've been to hell and back, and haven't managed to pinpoint all of the exact dependencies that cause the build to leak (or more likely: attempt to over... — committed to espoon-voltti/evaka by mikkopiu 3 years ago
- Rollback to ts 4.2.3 due to https://github.com/microsoft/TypeScript/issues/44281 — committed to quolpr/harika by quolpr 3 years ago
I think you might have better luck if you open a new issue with a playground link to the case that gets broken. as a matter of fact the two reproductions listed in the first post have been fixed in 4.4,so your issue might be because of another reason
@ahejlsberg, the issue still happening with 4.4.2. Could you reopen the issue?
Still happening with 4.4.1-rc.
Unclear if this is working as intended, but it might be a regression.