From a919a42a0e5bce8de2bd776c3ef5515386fc43f6 Mon Sep 17 00:00:00 2001 From: Roman Bruckner Date: Fri, 31 May 2024 14:19:27 +0200 Subject: [PATCH] types(dia.Cell): allow partial attributes with prop() and constructor() (#2667) --- packages/joint-core/test/ts/index.test.ts | 8 ++++++++ packages/joint-core/types/joint.d.ts | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/joint-core/test/ts/index.test.ts b/packages/joint-core/test/ts/index.test.ts index e76a0a37f..e458c7ad6 100644 --- a/packages/joint-core/test/ts/index.test.ts +++ b/packages/joint-core/test/ts/index.test.ts @@ -190,3 +190,11 @@ joint.connectors.curve({ x: 0, y: 0 }, { x: 20, y: 20 }, [], { targetDirection: joint.connectors.curve.TangentDirections.CLOSEST_POINT, direction: joint.connectors.curve.Directions.HORIZONTAL }); + +/* Partial attributes */ + +rectangle.prop({ size: { width: 100 }}); + +new joint.shapes.standard.Rectangle({ + position: { x: 100 }, +}); diff --git a/packages/joint-core/types/joint.d.ts b/packages/joint-core/types/joint.d.ts index 786f39f8b..91a2a4633 100644 --- a/packages/joint-core/types/joint.d.ts +++ b/packages/joint-core/types/joint.d.ts @@ -12,6 +12,16 @@ export namespace config { type NativeEvent = Event; +type _DeepRequired = { + [P in keyof T]-?: T[P] extends object ? _DeepRequired : T[P]; +}; + +type _DeepPartial = { + [P in keyof T]?: T[P] extends object ? _DeepPartial : T[P]; +}; + +type DeepPartial = _DeepPartial<_DeepRequired>; + export namespace dia { type Event = mvc.TriggeredEvent; @@ -327,7 +337,7 @@ export namespace dia { class Cell extends mvc.Model { - constructor(attributes?: A, opt?: Cell.ConstructorOptions); + constructor(attributes?: DeepPartial, opt?: Cell.ConstructorOptions); id: Cell.ID; graph: Graph; @@ -361,7 +371,7 @@ export namespace dia { isEmbedded(): boolean; prop(key: Path): any; - prop(object: Partial, opt?: Cell.Options): this; + prop(object: DeepPartial, opt?: Cell.Options): this; prop(key: Path, value: any, opt?: Cell.Options): this; removeProp(path: Path, opt?: Cell.Options): this;