From 093b81a40339b2ca9364b951172b690be1204414 Mon Sep 17 00:00:00 2001 From: dej611 Date: Thu, 9 Feb 2023 13:59:06 +0100 Subject: [PATCH 1/2] :label: Little experiment with types --- .../src/chart_types/goal_chart/specs/index.ts | 3 ++- .../src/chart_types/heatmap/specs/heatmap.ts | 22 ++++++++++++------- .../layout/types/viewmodel_types.ts | 17 +++++++++----- packages/charts/src/utils/types.ts | 12 ++++++++++ 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 packages/charts/src/utils/types.ts diff --git a/packages/charts/src/chart_types/goal_chart/specs/index.ts b/packages/charts/src/chart_types/goal_chart/specs/index.ts index 4a65f47ee8..a049e1ec06 100644 --- a/packages/charts/src/chart_types/goal_chart/specs/index.ts +++ b/packages/charts/src/chart_types/goal_chart/specs/index.ts @@ -17,6 +17,7 @@ import { SpecType } from '../../../specs/constants'; import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_factory'; import { LabelAccessor, round, stripUndefined, ValueFormatter } from '../../../utils/common'; import { Logger } from '../../../utils/logger'; +import { Prettify } from '../../../utils/types'; import { defaultGoalSpec } from '../layout/types/viewmodel_types'; /** @alpha */ @@ -130,4 +131,4 @@ To prevent overlapping, the value of \`angleEnd\` will be replaced. }; /** @public */ -export type GoalProps = ComponentProps; +export type GoalProps = Prettify>; diff --git a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts index 4cb8c05f09..7f705277e6 100644 --- a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts +++ b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts @@ -19,6 +19,7 @@ import { buildSFProps, SFProps, useSpecFactory } from '../../../state/spec_facto import { Accessor, AccessorFn } from '../../../utils/accessor'; import { ESCalendarInterval, ESFixedInterval } from '../../../utils/chrono/elasticsearch'; import { Datum, LabelAccessor, stripUndefined, ValueFormatter } from '../../../utils/common'; +import { Prettify } from '../../../utils/types'; import { Cell } from '../layout/types/viewmodel_types'; /** @public */ @@ -55,11 +56,13 @@ export interface TimeScale { type: typeof ScaleType.Time; } -/** @public */ -export interface RasterTimeScale extends TimeScale { +interface RasterTimeScaleInt extends TimeScale { interval: ESCalendarInterval | ESFixedInterval; } +/** @public */ +export type RasterTimeScale = Prettify; + /** @public */ export interface LinearScale { type: typeof ScaleType.Linear; @@ -70,8 +73,8 @@ export interface OrdinalScale { type: typeof ScaleType.Ordinal; } -/** @alpha */ -export interface HeatmapSpec extends Spec { +/** @internal */ +interface HeatmapSpecInternal extends Spec { specType: typeof SpecType.Series; chartType: typeof ChartType.Heatmap; data: D[]; @@ -94,8 +97,11 @@ export interface HeatmapSpec extends Spec { yAxisLabelName: string; yAxisLabelFormatter: LabelAccessor; } +/** @public */ +export type HeatmapSpec = Prettify; -const buildProps = buildSFProps()( +/** @internal */ +export const buildProps = buildSFProps()( { chartType: ChartType.Heatmap, specType: SpecType.Series, @@ -126,7 +132,7 @@ const buildProps = buildSFProps()( */ export const Heatmap = function ( props: SFProps< - HeatmapSpec, + HeatmapSpecInternal, keyof (typeof buildProps)['overrides'], keyof (typeof buildProps)['defaults'], keyof (typeof buildProps)['optionals'], @@ -134,9 +140,9 @@ export const Heatmap = function ( >, ) { const { defaults, overrides } = buildProps; - useSpecFactory>({ ...defaults, ...stripUndefined(props), ...overrides }); + useSpecFactory>({ ...defaults, ...stripUndefined(props), ...overrides }); return null; }; /** @public */ -export type HeatmapProps = ComponentProps; +export type HeatmapProps = Prettify>; diff --git a/packages/charts/src/chart_types/partition_chart/layout/types/viewmodel_types.ts b/packages/charts/src/chart_types/partition_chart/layout/types/viewmodel_types.ts index a4cbc67b84..ec04868294 100644 --- a/packages/charts/src/chart_types/partition_chart/layout/types/viewmodel_types.ts +++ b/packages/charts/src/chart_types/partition_chart/layout/types/viewmodel_types.ts @@ -26,6 +26,7 @@ import { LegendPath } from '../../../../state/actions/legend'; import { Size } from '../../../../utils/dimensions'; import { LIGHT_THEME } from '../../../../utils/themes/light_theme'; import { Theme } from '../../../../utils/themes/theme'; +import { Prettify } from '../../../../utils/types'; import { ContinuousDomainFocus } from '../../renderer/canvas/partition'; import { Layer } from '../../specs'; import { MODEL_KEY, ValueGetterName } from '../config'; @@ -235,10 +236,7 @@ export interface LayerFromTo { y1: TreeLevel; } -/** - * @public - */ -export interface TreeNode extends AngleFromTo { +interface TreeNodeInternal extends AngleFromTo { x0: Radian; x1: Radian; y0: TreeLevel; @@ -246,6 +244,11 @@ export interface TreeNode extends AngleFromTo { fill?: Color; } +/** + * @public + */ +export type TreeNode = Prettify; + /** * @public */ @@ -257,8 +260,7 @@ export interface SectorGeomSpecY { /** @public */ export type DataName = CategoryKey; // todo consider narrowing it to eg. primitives -/** @public */ -export interface ShapeTreeNode extends TreeNode, SectorGeomSpecY { +interface ShapeTreeNodeInternal extends TreeNode, SectorGeomSpecY { yMidPx: Distance; depth: number; sortIndex: number; @@ -268,6 +270,9 @@ export interface ShapeTreeNode extends TreeNode, SectorGeomSpecY { [MODEL_KEY]: ArrayNode; } +/** @public */ +export type ShapeTreeNode = Prettify; + /** @public */ export type RawTextGetter = (node: ShapeTreeNode) => string; /** @public */ diff --git a/packages/charts/src/utils/types.ts b/packages/charts/src/utils/types.ts new file mode 100644 index 0000000000..74befcf93a --- /dev/null +++ b/packages/charts/src/utils/types.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +/** + * @internal + */ +export type Prettify = T extends Function ? T : T extends object ? { [K in keyof T]: Prettify } & {} : T; From 8c3769e06aa76696b711d62acc7ea3d18dd93e8d Mon Sep 17 00:00:00 2001 From: dej611 Date: Thu, 9 Feb 2023 14:05:48 +0100 Subject: [PATCH 2/2] :label: Fix type check --- packages/charts/src/chart_types/heatmap/specs/heatmap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts index 7f705277e6..f9fbe37767 100644 --- a/packages/charts/src/chart_types/heatmap/specs/heatmap.ts +++ b/packages/charts/src/chart_types/heatmap/specs/heatmap.ts @@ -98,7 +98,7 @@ interface HeatmapSpecInternal extends Spec { yAxisLabelFormatter: LabelAccessor; } /** @public */ -export type HeatmapSpec = Prettify; +export type HeatmapSpec = Prettify>; /** @internal */ export const buildProps = buildSFProps()(