Skip to content

Commit

Permalink
types(dia.Cell): allow partial attributes with prop() and constructor…
Browse files Browse the repository at this point in the history
…() (#2667)
  • Loading branch information
kumilingus authored May 31, 2024
1 parent 66442ad commit a919a42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/joint-core/test/ts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
14 changes: 12 additions & 2 deletions packages/joint-core/types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ export namespace config {

type NativeEvent = Event;

type _DeepRequired<T> = {
[P in keyof T]-?: T[P] extends object ? _DeepRequired<T[P]> : T[P];
};

type _DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? _DeepPartial<T[P]> : T[P];
};

type DeepPartial<T> = _DeepPartial<_DeepRequired<T>>;

export namespace dia {

type Event = mvc.TriggeredEvent;
Expand Down Expand Up @@ -327,7 +337,7 @@ export namespace dia {

class Cell<A extends ObjectHash = Cell.Attributes, S extends mvc.ModelSetOptions = dia.ModelSetOptions> extends mvc.Model<A, S> {

constructor(attributes?: A, opt?: Cell.ConstructorOptions);
constructor(attributes?: DeepPartial<A>, opt?: Cell.ConstructorOptions);

id: Cell.ID;
graph: Graph;
Expand Down Expand Up @@ -361,7 +371,7 @@ export namespace dia {
isEmbedded(): boolean;

prop(key: Path): any;
prop(object: Partial<A>, opt?: Cell.Options): this;
prop(object: DeepPartial<A>, opt?: Cell.Options): this;
prop(key: Path, value: any, opt?: Cell.Options): this;

removeProp(path: Path, opt?: Cell.Options): this;
Expand Down

0 comments on commit a919a42

Please sign in to comment.