Skip to content

Commit 6889f3a

Browse files
committed
Update Circle.fromObject typing and usage
Refactored the types for Circle.fromObject to use Parameters<typeof TwoElement.fromObject>[0] and made matrix optional. Updated the test to use 'stroke', 'fill', and 'translation' instead of 'position'.
1 parent 88c4c91 commit 6889f3a

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

tests/typescript/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ let path;
99

1010
path = Two.Circle.fromObject({
1111
radius: 5,
12-
rotation: Math.PI,
13-
position: { x: 0, y: 0 },
12+
stroke: 'blue',
13+
fill: 'yellow',
14+
// position: new Two.Vector(),
15+
rotation: 5,
16+
translation: { x: 0, y: 0 },
1417
});
1518

1619
path = new Two.Line(5, 5, 10, 10);

tests/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"two.js": "file:../../",
1313
"typescript": "^5.2.2"
1414
}
15-
}
15+
}

types.d.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,24 +1253,23 @@ declare module 'two.js/src/shape' {
12531253
* @nota-bene Works in conjunction with {@link Two.Shape#toObject}
12541254
*/
12551255
static fromObject(
1256-
obj:
1257-
| object
1258-
| ((
1259-
| {
1260-
translation?: { x: number; y: number } | Vector;
1261-
position?: never;
1262-
}
1263-
| {
1264-
position?: { x: number; y: number } | Vector;
1265-
translation?: never;
1266-
}
1267-
) & {
1268-
rotation?: number;
1269-
scale?: number | { x: number; y: number } | Vector;
1270-
skewX?: number;
1271-
skewY?: number;
1272-
matrix: Parameters<typeof Matrix.fromObject>[0];
1273-
})
1256+
obj: Parameters<typeof TwoElement.fromObject>[0] &
1257+
((
1258+
| {
1259+
translation?: { x: number; y: number } | Vector;
1260+
position?: never;
1261+
}
1262+
| {
1263+
position?: { x: number; y: number } | Vector;
1264+
translation?: never;
1265+
}
1266+
) & {
1267+
rotation?: number;
1268+
scale?: number | { x: number; y: number } | Vector;
1269+
skewX?: number;
1270+
skewY?: number;
1271+
matrix?: Parameters<typeof Matrix.fromObject>[0];
1272+
})
12741273
): Shape;
12751274
/**
12761275
* @name Two.Shape#_flagMatrix

0 commit comments

Comments
 (0)