-
Notifications
You must be signed in to change notification settings - Fork 30.6k
[d3-axis and d3-format] activate strictNullChecks and strictFunctionTypes #24305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
21299f9
a97b6fe
12461ad
ee100da
6c309cd
900c476
278b13f
e164c7d
559a1f7
411b81f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ axisScaleNumber = scaleBand<number>(); | |
| axisScaleNumber = scalePoint<number>(); | ||
| axisScaleString = scaleBand(); | ||
| axisScaleString = scalePoint(); | ||
|
|
||
| // -------------------------------------------------------------------------- | ||
| // Test AxisContainerElement | ||
| // -------------------------------------------------------------------------- | ||
|
|
@@ -58,7 +59,8 @@ const canvas: HTMLCanvasElement = select<HTMLCanvasElement, any>('canvas').node( | |
|
|
||
| containerElement = svg; | ||
| containerElement = g; | ||
| // containerElement = canvas; // fails, incompatible type | ||
| // $ExpectError | ||
| containerElement = canvas; // fails, incompatible type | ||
|
|
||
| // -------------------------------------------------------------------------- | ||
| // Test Axis Generators | ||
|
|
@@ -77,14 +79,17 @@ let leftAxis: d3Axis.Axis<number | { valueOf(): number }> = d3Axis.axisLeft(scal | |
|
|
||
| leftAxis = leftAxis.scale(scalePow()); | ||
| const powerScale: ScalePower<number, number> = leftAxis.scale<ScalePower<number, number>>(); | ||
| // powerScale = leftAxis.scale(); // fails, without casting as AxisScale is purposely generic | ||
| // $ExpectError | ||
| const powerScale2 = leftAxis.scale(); // fails, without casting as AxisScale is purposely generic | ||
|
|
||
| bottomAxis = bottomAxis.scale(scaleOrdinal<number>()); | ||
| // bottomAxis = bottomAxis.scale(scalePow()) // fails, domain of scale incompatible with domain of axis | ||
| // $ExpectError | ||
| bottomAxis = bottomAxis.scale(scalePow()); // fails, domain of scale incompatible with domain of axis | ||
|
|
||
| const axisScale: d3Axis.AxisScale<string> = bottomAxis.scale(); | ||
| const ordinalScale: ScaleOrdinal<string, number> = bottomAxis.scale<ScaleOrdinal<string, number>>(); | ||
| // ordinalScale = bottomAxis.scale(); // fails, without casting as AxisScale is purposely generic | ||
| // $ExpectError | ||
| const ordinalScale2 = bottomAxis.scale(); // fails, without casting as AxisScale is purposely generic | ||
|
|
||
| // ticks(...) ---------------------------------------------------------------- | ||
|
|
||
|
|
@@ -119,6 +124,7 @@ const formatFn: ((domainValue: string, index: number) => string) | null = bottom | |
|
|
||
| bottomAxis.tickFormat((d, i) => '#' + i); | ||
| bottomAxis.tickFormat(d => d + '!'); | ||
|
|
||
| // tickSize(...) ---------------------------------------------------------------- | ||
|
|
||
| rightAxis = rightAxis.tickSize(5); | ||
|
|
@@ -149,14 +155,24 @@ const gTransition = gSelection.transition(); | |
| gSelection.call(topAxis); | ||
| gTransition.call(topAxis); | ||
|
|
||
| const svgSelection: Selection<SVGSVGElement, any, any, any> = select<SVGSVGElement, any>('g'); | ||
| const svgSelection: Selection<SVGSVGElement, any, any, any> = select<SVGSVGElement, any>('svg'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 😄 Now that's attention to detail! |
||
| const svgTransition = svgSelection.transition(); | ||
|
|
||
| svgSelection.call(leftAxis); | ||
| svgTransition.call(leftAxis); | ||
|
|
||
| const pathSelection: Selection<SVGPathElement, any, any, any> = select<SVGPathElement, any>('path'); | ||
| const pathTransition = svgSelection.transition(); | ||
|
|
||
| // $ExpectError | ||
| pathSelection.call(bottomAxis); | ||
| // $ExpectError | ||
| pathSelection.call(bottomAxis); | ||
|
|
||
| const canvasSelection: Selection<HTMLCanvasElement, any, any, any> = select<HTMLCanvasElement, any>('canvas'); | ||
| const canvasTransition = canvasSelection.transition(); | ||
|
|
||
| // canvasSelection.call(rightAxis); // fails, incompatible context container element | ||
| // canvasTransition.call(rightAxis); // fails, incompatible context container element | ||
| // $ExpectError | ||
| canvasSelection.call(rightAxis); // fails, incompatible context container element | ||
| // $ExpectError | ||
| canvasTransition.call(rightAxis); // fails, incompatible context container element | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,43 +29,43 @@ export interface AxisTimeInterval { | |
|
|
||
| /** | ||
| * A helper interface to which a scale passed into axis must conform (at a minimum) | ||
| * for axis to use the scale without error | ||
| * for axis to use the scale without error. | ||
| */ | ||
| export interface AxisScale<Domain> { | ||
| (x: Domain): number | undefined; | ||
| domain(): Domain[]; | ||
| range(): number[]; | ||
| copy(): this; | ||
| bandwidth?(): number; | ||
| // TODO: Reconsider the below, note that the compiler does not differentiate the overloads w.r.t. optionality | ||
| // TODO: Reconsider the below, note that the compiler does not differentiate the overloads w.r.t. optionality | ||
| // ticks?(count?: number): Domain[]; | ||
| // ticks?(count?: AxisTimeInterval): Date[]; | ||
| // tickFormat?(count?: number, specifier?: string): ((d: number) => string); | ||
| // tickFormat?(count?: number | AxisTimeInterval, specifier?: string): ((d: Date) => string); | ||
| } | ||
|
|
||
| /** | ||
| * A helper type to alias elements which can serve as a container for an axis | ||
| * A helper type to alias elements which can serve as a container for an axis. | ||
| */ | ||
| export type AxisContainerElement = SVGSVGElement | SVGGElement; | ||
|
|
||
| /** | ||
| * Interface defining an axis generator. The generic <Domain> is the type of the axis domain | ||
| * Interface defining an axis generator. The generic <Domain> is the type of the axis domain. | ||
| */ | ||
| export interface Axis<Domain> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will review the constraints on We could have |
||
| /** | ||
| * Render the axis to the given context. | ||
| * | ||
| * @param context A selection of SVG containers (either SVG or G elements). | ||
| */ | ||
| (context: Selection<AxisContainerElement, any, any, any>): void; | ||
| (context: Selection<SVGSVGElement, any, any, any> | Selection<SVGGElement, any, any, any>): void; | ||
|
|
||
| /** | ||
| * Render the axis to the given context. | ||
| * | ||
| * @param context A transition defined on SVG containers (either SVG or G elements). | ||
| */ | ||
| (context: TransitionLike<AxisContainerElement, any>): void; | ||
| (context: TransitionLike<SVGSVGElement, any> | TransitionLike<SVGGElement, any>): void; | ||
|
|
||
| /** | ||
| * Gets the current scale underlying the axis. | ||
|
|
@@ -75,7 +75,7 @@ export interface Axis<Domain> { | |
| /** | ||
| * Sets the scale and returns the axis. | ||
| * | ||
| * @param scale The scale to be used for axis generation | ||
| * @param scale The scale to be used for axis generation. | ||
| */ | ||
| scale(scale: AxisScale<Domain>): this; | ||
|
|
||
|
|
@@ -86,7 +86,7 @@ export interface Axis<Domain> { | |
| * | ||
| * This method is also a convenience function for axis.tickArguments. | ||
| * | ||
| * @param count Number of ticks that should be rendered | ||
| * @param count Number of ticks that should be rendered. | ||
| * @param specifier An optional format specifier to customize how the tick values are formatted. | ||
| */ | ||
| ticks(count: number, specifier?: string): this; | ||
|
|
@@ -178,7 +178,7 @@ export interface Axis<Domain> { | |
| * | ||
| * See also axis.ticks. | ||
| * | ||
| * @param args An array with arguments suitable for the scale to be used for tick generation | ||
| * @param args An array with arguments suitable for the scale to be used for tick generation. | ||
| */ | ||
| tickArguments(args: any[]): this; | ||
|
|
||
|
|
@@ -210,7 +210,7 @@ export interface Axis<Domain> { | |
| tickFormat(): ((domainValue: Domain, index: number) => string) | null; | ||
|
|
||
| /** | ||
| * Sets the tick format function and returns the axis. | ||
| * Sets the tick format function and returns the axis. | ||
| * | ||
| * @param format A function mapping a value from the axis Domain to a formatted string | ||
| * for display purposes. When invoked, the format function is also passed a second argument representing the zero-based index | ||
|
|
@@ -287,7 +287,7 @@ export interface Axis<Domain> { | |
| /** | ||
| * Set the current padding and return the axis. | ||
| * | ||
| * @param padding Padding in pixels (Default is 3). | ||
| * @param padding Padding in pixels (Default is 3). | ||
| */ | ||
| tickPadding(padding: number): this; | ||
| } | ||
|
|
@@ -296,30 +296,30 @@ export interface Axis<Domain> { | |
| * Constructs a new top-oriented axis generator for the given scale, with empty tick arguments, | ||
| * a tick size of 6 and padding of 3. In this orientation, ticks are drawn above the horizontal domain path. | ||
| * | ||
| * @param scale The scale to be used for axis generation | ||
| * @param scale The scale to be used for axis generation. | ||
| */ | ||
| export function axisTop<Domain>(scale: AxisScale<Domain>): Axis<Domain>; | ||
|
|
||
| /** | ||
| * Constructs a new right-oriented axis generator for the given scale, with empty tick arguments, | ||
| * a tick size of 6 and padding of 3. In this orientation, ticks are drawn to the right of the vertical domain path. | ||
| * | ||
| * @param scale The scale to be used for axis generation | ||
| * @param scale The scale to be used for axis generation. | ||
| */ | ||
| export function axisRight<Domain>(scale: AxisScale<Domain>): Axis<Domain>; | ||
|
|
||
| /** | ||
| * Constructs a new bottom-oriented axis generator for the given scale, with empty tick arguments, | ||
| * a tick size of 6 and padding of 3. In this orientation, ticks are drawn below the horizontal domain path. | ||
| * | ||
| * @param scale The scale to be used for axis generation | ||
| * @param scale The scale to be used for axis generation. | ||
| */ | ||
| export function axisBottom<Domain>(scale: AxisScale<Domain>): Axis<Domain>; | ||
|
|
||
| /** | ||
| * Constructs a new left-oriented axis generator for the given scale, with empty tick arguments, | ||
| * a tick size of 6 and padding of 3. In this orientation, ticks are drawn to the left of the vertical domain path. | ||
| * | ||
| * @param scale The scale to be used for axis generation | ||
| * @param scale The scale to be used for axis generation. | ||
| */ | ||
| export function axisLeft<Domain>(scale: AxisScale<Domain>): Axis<Domain>; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting to use this dts-lint feature. We should start using this across the board on all the "fail" tests in D3. We had to historically comment them out (and manually check during definition updates). So let's roll with
$ExpectError