Skip to content

Commit 1b0fe2b

Browse files
committed
[d3-3d] use overloads instead of conditional types
1 parent 7d8b071 commit 1b0fe2b

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

types/d3-3d/index.d.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export interface Shape3DGenerator<ShapeInput, Shape = ShapeInput> {
99
*
1010
* @param data The data representing the 3D shapes.
1111
* @returns An array of 3D shapes generated with the specified parameters and transformations.
12-
*
1312
*/
1413
(data: ShapeInput[]): Shape[];
1514

@@ -19,77 +18,80 @@ export interface Shape3DGenerator<ShapeInput, Shape = ShapeInput> {
1918
* @param o The origin point for rendering the 3D shapes.
2019
* @returns If no argument is provided, returns the current origin. Otherwise, sets the origin and returns the function.
2120
*/
22-
origin(o?: Coordinate2D): typeof o extends undefined ? Coordinate2D : Shape3DGenerator<ShapeInput, Shape>;
21+
origin(o: Coordinate2D): Shape3DGenerator<ShapeInput, Shape>;
22+
origin(): Coordinate2D;
2323

2424
/**
2525
* Sets or retrieves the scale factor for the 3D shapes.
2626
*
2727
* @param s The scale factor for the 3D shapes.
2828
* @returns If no argument is provided, returns the current scale factor. Otherwise, sets the scale factor and returns the function.
2929
*/
30-
scale(s?: number): typeof s extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
30+
scale(s: number): Shape3DGenerator<ShapeInput, Shape>;
31+
scale(): number;
3132

3233
/**
3334
* Sets or retrieves the rotation angle around the x-axis.
3435
*
3536
* @param ax The rotation angle around the x-axis.
3637
* @returns If no argument is provided, returns the current rotation angle around the x-axis. Otherwise, sets the rotation angle and returns the function.
3738
*/
38-
rotateX(ax?: number): typeof ax extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
39+
rotateX(ax: number): Shape3DGenerator<ShapeInput, Shape>;
40+
rotateX(): number;
3941

4042
/**
4143
* Sets or retrieves the rotation angle around the y-axis.
4244
*
4345
* @param ay The rotation angle around the y-axis.
4446
* @returns If no argument is provided, returns the current rotation angle around the y-axis. Otherwise, sets the rotation angle and returns the function.
4547
*/
46-
rotateY(ay?: number): typeof ay extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
48+
rotateY(ay: number): Shape3DGenerator<ShapeInput, Shape>;
49+
rotateY(): number;
4750

4851
/**
4952
* Sets or retrieves the rotation angle around the z-axis.
5053
*
5154
* @param az The rotation angle around the z-axis.
5255
* @returns If no argument is provided, returns the current rotation angle around the z-axis. Otherwise, sets the rotation angle and returns the function.
5356
*/
54-
rotateZ(az?: number): typeof az extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
57+
rotateZ(az: number): Shape3DGenerator<ShapeInput, Shape>;
58+
rotateZ(): number;
5559

5660
/**
5761
* Sets or retrieves the rotation center for the 3D shapes.
5862
*
5963
* @param rc The rotation center for the 3D shapes.
6064
* @returns If no argument is provided, returns the current rotation center. Otherwise, sets the rotation center and returns the function.
6165
*/
62-
rotationCenter(rc?: Coordinate3D): typeof rc extends undefined ? Coordinate3D : Shape3DGenerator<ShapeInput, Shape>;
66+
rotationCenter(rc: Coordinate3D): Shape3DGenerator<ShapeInput, Shape>;
67+
rotationCenter(): Coordinate3D;
6368

6469
/**
6570
* Sets or retrieves the x-coordinate for the 3D shapes.
6671
*
6772
* @param px The x-coordinate for the 3D shapes.
6873
* @returns If no argument is provided, returns the current x-coordinate. Otherwise, sets the x-coordinate and returns the function.
6974
*/
70-
x(
71-
px?: number | ((p: Point3D) => number)
72-
): typeof px extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
75+
x(px: number | ((p: Point3D) => number)): Shape3DGenerator<ShapeInput, Shape>;
76+
x(): number;
7377

7478
/**
7579
* Sets or retrieves the y-coordinate for the 3D shapes.
7680
*
7781
* @param py The y-coordinate for the 3D shapes.
7882
* @returns If no argument is provided, returns the current y-coordinate. Otherwise, sets the y-coordinate and returns the function.
7983
*/
80-
y(
81-
py?: number | ((p: Point3D) => number)
82-
): typeof py extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
84+
y(py: number | ((p: Point3D) => number)): Shape3DGenerator<ShapeInput, Shape>;
85+
y(): number;
8386

8487
/**
8588
* Sets or retrieves the z-coordinate for the 3D shapes.
8689
*
8790
* @param pz The z-coordinate for the 3D shapes.
8891
* @returns If no argument is provided, returns the current z-coordinate. Otherwise, sets the z-coordinate and returns the function.
8992
*/
90-
z(
91-
pz?: number | ((p: Point3D) => number)
92-
): typeof pz extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
93+
z(pz: number | ((p: Point3D) => number)): Shape3DGenerator<ShapeInput, Shape>;
94+
z(): number;
9395

9496
/**
9597
* !IMPORT! ONLY FOR gridplanes
@@ -98,7 +100,8 @@ export interface Shape3DGenerator<ShapeInput, Shape = ShapeInput> {
98100
* @param pz The z-coordinate for the 3D shapes.
99101
* @returns If no argument is provided, returns the current rows. Otherwise, sets the rows and returns the function.
100102
*/
101-
rows(pz?: number): typeof pz extends undefined ? number : Shape3DGenerator<ShapeInput, Shape>;
103+
rows(pz: number): Shape3DGenerator<ShapeInput, Shape>;
104+
rows(): number;
102105

103106
/**
104107
* Comparator function to sort objects based on their centroid z-values.
@@ -257,7 +260,7 @@ export type Cube3DInput = [
257260
Point3DInput,
258261
Point3DInput,
259262
Point3DInput,
260-
Point3DInput
263+
Point3DInput,
261264
];
262265

263266
/**
@@ -280,13 +283,19 @@ export function _3d<Shape3DInput, Shape3D>(): Shape3DGenerator<Shape3DInput, Sha
280283
* @param s The shape for the 3D generator.
281284
* @returns If no argument is provided, returns the current shape. Otherwise, sets the shape and returns the function.
282285
*/
283-
shape(
284-
s?: ShapeKind,
285-
row?: number
286-
): typeof s extends undefined ? ShapeKind : Shape3DGenerator<Shape3DInput, Shape3D>;
286+
shape(s: ShapeKind, row?: number): Shape3DGenerator<Shape3DInput, Shape3D>;
287+
shape(): ShapeKind;
287288
};
288289

289-
export type ShapeKind = "CUBE" | "GRID" | "LINE" | "LINE_STRIP" | "PLANE" | "POINT" | "SURFACE" | "TRIANGLE";
290+
export type ShapeKind =
291+
| "CUBE"
292+
| "GRID"
293+
| "LINE"
294+
| "LINE_STRIP"
295+
| "PLANE"
296+
| "POINT"
297+
| "SURFACE"
298+
| "TRIANGLE";
290299

291300
/**
292301
* Creates a new 3D generator for drawing points.

0 commit comments

Comments
 (0)