Closed
Description
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