Skip to content

Commit bd58774

Browse files
committed
more type specificity
1 parent 6bb5661 commit bd58774

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/interval.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export interface NiceIntervalImplementation<T> extends RangeIntervalImplementati
8282
type LiteralInterval<T> = T extends Date ? TimeIntervalName : T extends number ? number : never;
8383

8484
/** How to partition a continuous range into discrete intervals. */
85-
export type Interval<T = any> = LiteralInterval<T> | IntervalImplementation<T>;
85+
export type Interval<T = number | Date> = LiteralInterval<T> | IntervalImplementation<T>;
8686

8787
/** An interval that supports the range method, say for thresholds or ticks. */
88-
export type RangeInterval<T = any> = LiteralInterval<T> | RangeIntervalImplementation<T>;
88+
export type RangeInterval<T = number | Date> = LiteralInterval<T> | RangeIntervalImplementation<T>;
8989

9090
/** An interval that can be used to nice a scale domain. */
91-
export type NiceInterval<T = any> = LiteralInterval<T> | NiceIntervalImplementation<T>;
91+
export type NiceInterval<T = number | Date> = LiteralInterval<T> | NiceIntervalImplementation<T>;

src/reducer.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export type ReducerName =
2525
| "mode"
2626
| ReducerPercentile;
2727

28-
export type ReducerFunction = (values: any[]) => any;
28+
export type ReducerFunction<S = any, T = S> = (values: S[]) => T;
2929

30-
// TODO scope, label
31-
export interface ReducerImplementation {
32-
reduceIndex(index: number[], values: any[]): any;
30+
export interface ReducerImplementation<S = any, T = S> {
31+
reduceIndex(index: number[], values: S[]): T;
32+
// TODO scope
33+
// TODO label
3334
}
3435

3536
/** How to reduce aggregated values. */

src/transforms/bin.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import type {Transformed} from "./basic.js";
77
export type ThresholdsName = "freedman-diaconis" | "scott" | "sturges" | "auto";
88

99
/** How to subdivide a continuous domain into discrete bins (based on data). */
10-
export type ThresholdsFunction = (values: any[], min: any, max: any) => any[] | RangeInterval | number;
10+
export type ThresholdsFunction<T = number | Date> = (values: T[], min: T, max: T) => T[] | RangeInterval<T> | number;
1111

1212
/** How to subdivide a continuous domain into discrete bins. */
13-
export type Thresholds = ThresholdsName | ThresholdsFunction | RangeInterval | any[];
13+
export type Thresholds<T = number | Date> = ThresholdsName | ThresholdsFunction<T> | RangeInterval<T> | T[] | number;
1414

1515
/** Options for the bin transform. */
16-
export interface BinOptions {
16+
export interface BinOptions<T = number | Date> {
1717
/**
1818
* If true or a positive number, produce a cumulative distribution; if a
1919
* negative number, produce a [complementary cumulative](https://en.wikipedia.org/wiki/Cumulative_distribution_function#Complementary_cumulative_distribution_function_.28tail_distribution.29)
@@ -30,7 +30,7 @@ export interface BinOptions {
3030
* domain is used, the start and end of the domain will be extended to align
3131
* with the interval.
3232
*/
33-
domain?: ((values: any[]) => [min: any, max: any]) | [min: any, max: any];
33+
domain?: ((values: T[]) => [min: T, max: T]) | [min: T, max: T];
3434

3535
/**
3636
* How to subdivide the domain into bins. May be one of:
@@ -44,7 +44,7 @@ export interface BinOptions {
4444
* * an interval; see **interval**
4545
* * a function that returns an array, count, or interval
4646
*/
47-
thresholds?: Thresholds;
47+
thresholds?: Thresholds<T>;
4848

4949
/**
5050
* How to subdivide the domain into bins; an alternative to **thresholds**.
@@ -53,7 +53,7 @@ export interface BinOptions {
5353
* number *n*, threshold values are consecutive multiples of *n* that span the
5454
* domain.
5555
*/
56-
interval?: RangeInterval;
56+
interval?: RangeInterval<T>;
5757
}
5858

5959
/** How to reduce binned values. */

0 commit comments

Comments
 (0)