АГ
Size: a a a
АГ
АГ
Р
Р
˸A
АГ
АГ
Р
VS
˸A
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 // Property 'tracking' does not exist on type '{ comment: string; }'
console.log(a.withTrackingNumber(1234).withSpecialComment().build().tracking)
АГ
˸A
АГ
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 // Property 'tracking' does not exist on type '{ comment: string; }'
console.log(a.withTrackingNumber(1234).withSpecialComment().build().tracking)
АГ
Р
˸A
АГ
АГ
Р
АГ