Skip to content

Broken inferred recursive typesΒ #43817

Closed
Closed
@blackakula

Description

@blackakula

Bug Report

TypeScript inference on recursive types is broken since v4.1

πŸ”Ž Search Terms

  • inferred
  • recursive

πŸ•— Version & Regression Information

  • This changed between versions 4.0.5 and 4.1.5

⏯ Playground Link

Playground link with 4.3.0-beta - with the TS errors

Playground link with 4.0.5 - no errors

πŸ’» Code

const Builder = <T extends {}>(model: T) => ({
    withComment: (comment: string) => Builder({ ...model, comment }),
    withSpecialComment: () => Builder(model).withComment('Special comment'),
    withTrackingNumber: (tracking: number) => Builder({ ...model, tracking }),
    build: () => model })

const a = Builder({});
// a.withComment('test').build().tracking // OK - expected "Property 'tracking' does not exist on type '{ comment: string; }'""
console.log(a.withTrackingNumber(1234).withSpecialComment().build().tracking)

πŸ™ Actual behavior

TS compiler error: "The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.(7056)"

πŸ™‚ Expected behavior

No errors on compilation

Metadata

Metadata

Assignees

Labels

Design LimitationConstraints of the existing architecture prevent this from being fixed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions