diff --git a/types/recharts/index.d.ts b/types/recharts/index.d.ts index 0eed7d02db..146a1b4d56 100644 --- a/types/recharts/index.d.ts +++ b/types/recharts/index.d.ts @@ -28,13 +28,13 @@ export type Percentage = string; export type RechartsFunction = (...args: any[]) => void; export type LegendValueFormatter = (value?: LegendPayload['value'], entry?: LegendPayload, i?: number) => any; export type TickFormatterFunction = (value: any) => any; -export type TickGeneratorFunction = (noTicksProps: object) => any[]; +export type TickGeneratorFunction = (noTicksProps: object) => ReadonlyArray; export type LabelFormatter = (label: string | number) => React.ReactNode; export type TooltipFormatter = (value: string | number | Array, name: string, entry: TooltipPayload, index: number) => React.ReactNode; export type ItemSorter = (a: T, b: T) => number; export type ContentRenderer

= (props: P) => React.ReactNode; -export type DataKey = string | number | ((dataObject: any) => string | number | [number, number] | null); +export type DataKey = string | number | ((dataObject: any) => string | number | Readonly<[number, number]> | null); export type IconType = 'plainline' | 'line' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye' | 'plainline'; export type LegendType = IconType | 'none'; @@ -78,7 +78,7 @@ export interface ContainerSize { export interface Point { x: number; y: number; - value: number | any[]; + value: number | ReadonlyArray; } export interface Margin { @@ -192,9 +192,9 @@ export interface AreaProps extends EventAttributes, Partial | React.ReactElement; hide?: boolean; layout?: LayoutType; - baseLine?: number | any[]; + baseLine?: number | ReadonlyArray; isRange?: boolean; - points?: Point[]; + points?: ReadonlyArray; id?: string; } @@ -210,15 +210,15 @@ export interface BarData { y: number; width: number; height: number; - radius: number | any[]; - value: number | string | any[]; + radius: number | ReadonlyArray; + value: number | string | ReadonlyArray; } export interface BarProps extends EventAttributes, Partial, Animatable { dataKey: DataKey; // As the source code states, dataKey will replace valueKey in 1.1.0 and it'll be required (it's already required in current implementation). className?: string; fill?: string; - radius?: number | number[]; + radius?: number | ReadonlyArray; layout?: LayoutType; xAxisId?: string | number; yAxisId?: string | number; @@ -233,7 +233,7 @@ export interface BarProps extends EventAttributes, Partial; - data?: BarData[]; + data?: ReadonlyArray; background?: boolean | React.ReactElement | ContentRenderer | object; // see label section at http://recharts.org/#/en-US/api/Bar label?: boolean | Label | LabelProps | React.SFC | React.ReactElement | ContentRenderer; @@ -258,7 +258,7 @@ export interface BrushProps { travellerWidth?: number; padding?: Partial; dataKey?: DataKey; - data?: any[]; + data?: ReadonlyArray; startIndex?: number; endIndex?: number; tickFormatter?: TickFormatterFunction; @@ -284,7 +284,7 @@ export interface CartesianAxisProps extends EventAttributes, Partial; tickSize?: number; stroke?: string; tickFormatter?: TickFormatterFunction; @@ -299,7 +299,7 @@ export type CoordinatesGenerator = (arg: { width: CartesianGridProps['chartWidth']; height: CartesianGridProps['chartHeight']; offset: CartesianGridProps['offset']; -}) => number[]; +}) => ReadonlyArray; export interface CartesianGridProps extends Partial { y?: number; @@ -307,8 +307,8 @@ export interface CartesianGridProps extends Partial { height?: number; horizontal?: object | React.ReactElement | ContentRenderer | boolean; vertical?: object | React.ReactElement | ContentRenderer | boolean; - horizontalPoints?: number[]; - verticalPoints?: number[]; + horizontalPoints?: ReadonlyArray; + verticalPoints?: ReadonlyArray; horizontalCoordinatesGenerator?: CoordinatesGenerator; verticalCoordinatesGenerator?: CoordinatesGenerator; xAxis?: object; @@ -316,8 +316,8 @@ export interface CartesianGridProps extends Partial { offset?: object; chartWidth?: number; chartHeight?: number; - horizontalFill?: string[]; - verticalFill?: string[]; + horizontalFill?: ReadonlyArray; + verticalFill?: ReadonlyArray; } export class CartesianGrid extends React.Component { } @@ -350,8 +350,8 @@ export interface CurveProps extends EventAttributes, Partial; + points?: ReadonlyArray; connectNulls?: boolean; path?: string; pathRef?: React.Ref; @@ -373,7 +373,7 @@ export type DataPointFormatter = (entry: any, dataKey: DataKey) => { x: number; export interface ErrorBarProps { dataKey: DataKey; // As the source code states, dataKey will replace valueKey in 1.1.0 and it'll be required (it's already required in current implementation). - data?: any[]; + data?: ReadonlyArray; xAxis?: object; yAxis?: object; layout?: string; @@ -408,7 +408,7 @@ export interface LegendProps { align?: 'left' | 'center' | 'right'; verticalAlign?: 'top' | 'middle' | 'bottom'; margin?: Partial; - payload?: LegendPayload[]; + payload?: ReadonlyArray; formatter?: LegendValueFormatter; onClick?: RechartsFunction; onMouseEnter?: RechartsFunction; @@ -440,7 +440,7 @@ export interface LineProps extends EventAttributes, Partial; dataKey: DataKey; // As the source code states, dataKey will replace valueKey in 1.1.0 and it'll be required (it's already required in current implementation). label?: boolean | object | React.ReactElement | ContentRenderer; - points?: Point[]; + points?: ReadonlyArray; id?: string; } @@ -469,14 +469,14 @@ export interface PieProps extends EventAttributes, Partial; hide?: boolean; labelLine?: object | ContentRenderer | React.ReactElement | boolean; label?: { offsetRadius: number; } | React.ReactElement | ContentRenderer | boolean; activeShape?: object | ContentRenderer | React.ReactElement; - activeIndex?: number | number[]; + activeIndex?: number | ReadonlyArray; blendStroke?: boolean; } @@ -523,7 +523,7 @@ export interface PolarAngleAxisProps extends EventAttributes, Partial | object | React.ReactElement; - ticks?: PolarAngleAxisTick[]; + ticks?: ReadonlyArray; stroke?: string; orientation?: 'inner' | 'outer'; tickFormatter?: TickFormatterFunction; @@ -536,8 +536,8 @@ export interface PolarGridProps extends Partial { cy?: number; innerRadius?: number; outerRadius?: number; - polarAngles?: number[]; - polarRadius?: number[]; + polarAngles?: ReadonlyArray; + polarRadius?: ReadonlyArray; gridType?: 'polygon' | 'circle'; } @@ -558,13 +558,13 @@ export interface PolarRadiusAxisProps extends EventAttributes, Partial; orientation?: "left" | "right" | "middle"; axisLine?: boolean | object; tick?: boolean | object | React.ReactElement | ContentRenderer; stroke?: string; tickFormatter?: TickFormatterFunction; - domain?: [PolarRadiusAxisDomain, PolarRadiusAxisDomain]; + domain?: Readonly<[PolarRadiusAxisDomain, PolarRadiusAxisDomain]>; scale?: ScaleType | RechartsFunction; allowDataOverflow?: boolean; } @@ -578,7 +578,7 @@ export interface PolygonPoint { export interface PolygonProps extends EventAttributes, Partial { className?: string; - points?: PolygonPoint[]; + points?: ReadonlyArray; } export class Polygon extends React.Component { } @@ -598,7 +598,7 @@ export interface RadarProps extends EventAttributes, Partial; shape?: React.ReactElement | ContentRenderer; activeDot?: object | React.ReactElement | ContentRenderer | boolean; dot?: object | React.ReactElement | ContentRenderer | boolean; @@ -639,7 +639,7 @@ export interface RadialBarProps extends EventAttributes, Partial; legendType?: LegendType; label?: boolean | React.ReactElement | ContentRenderer | object; background?: boolean | React.ReactElement | ContentRenderer | object; @@ -665,7 +665,7 @@ export interface RectangleProps extends EventAttributes, Partial; } export class Rectangle extends React.Component { } @@ -776,7 +776,7 @@ export interface ScatterProps extends EventAttributes, Partial; - points?: ScatterPoint[]; + points?: ReadonlyArray; hide?: boolean; data?: ReadonlyArray; dataKey?: DataKey; @@ -841,7 +841,7 @@ export type AllowEscapeViewBox = { x: boolean } | { y: boolean } | { x: boolean, export interface TooltipPayload { name: string; - value: string | number | Array; + value: string | number | ReadonlyArray<(string | number)>; unit?: string; color?: string; fill?: string; @@ -867,7 +867,7 @@ export interface TooltipProps extends Animatable { position?: Coordinate; label?: string | number; labelFormatter?: LabelFormatter; - payload?: TooltipPayload[]; + payload?: ReadonlyArray; itemSorter?: ItemSorter; filterNull?: boolean; useTranslate3d?: boolean; @@ -878,7 +878,7 @@ export class Tooltip extends React.Component { } export interface TreemapProps extends EventAttributes, Animatable { width?: number; height?: number; - data?: any[]; + data?: ReadonlyArray; style?: object; aspectRatio?: number; content?: React.ReactElement | ContentRenderer; @@ -943,7 +943,7 @@ export interface XAxisProps extends EventAttributes { unit?: string | number; // The unique id of x-axis xAxisId?: string | number; - domain?: [AxisDomain, AxisDomain]; + domain?: Readonly<[AxisDomain, AxisDomain]>; // The key of data displayed in the axis dataKey?: DataKey; // The width of axis which is usually calculated internally @@ -962,7 +962,7 @@ export interface XAxisProps extends EventAttributes { type?: 'number' | 'category'; // Ticks can be any type when the axis is the type of category // Ticks must be numbers when the axis is the type of number - ticks?: any[]; + ticks?: ReadonlyArray; // The count of ticks tickCount?: number; // The formatter function of tick @@ -1003,12 +1003,12 @@ export interface YAxisProps extends EventAttributes { unit?: string | number; // The unique id of y-axis yAxisId?: string | number; - domain?: [AxisDomain, AxisDomain]; + domain?: Readonly<[AxisDomain, AxisDomain]>; // The key of data displayed in the axis dataKey?: DataKey; // Ticks can be any type when the axis is the type of category // Ticks must be numbers when the axis is the type of number - ticks?: any[]; + ticks?: ReadonlyArray; // The count of ticks tickCount?: number; // Rotation of tick labels @@ -1057,7 +1057,7 @@ export interface ZAxisProps { // The key of data displayed in the axis dataKey?: DataKey; // The range of axis - range?: number[]; + range?: ReadonlyArray; scale?: ScaleType | RechartsFunction; }