Skip to content

Commit

Permalink
Fix types (#78619)
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof authored and timroes committed Sep 28, 2020
1 parent 9cb30fb commit 91580f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/plugins/visualizations/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface VisToExpressionAstParams {
abortSignal?: AbortSignal;
}

export type VisToExpressionAst = (
vis: Vis,
export type VisToExpressionAst<TVisParams = VisParams> = (
vis: Vis<TVisParams>,
params: VisToExpressionAstParams
) => ExpressionAstExpression;
16 changes: 9 additions & 7 deletions src/plugins/visualizations/public/vis_types/base_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { VisToExpressionAst, VisualizationControllerConstructor } from '../types';
import { VisParams, VisToExpressionAst, VisualizationControllerConstructor } from '../types';
import { TriggerContextMapping } from '../../../ui_actions/public';
import { Adapters } from '../../../inspector/public';

Expand All @@ -43,8 +43,8 @@ interface CommonBaseVisTypeOptions {
inspectorAdapters?: Adapters | (() => Adapters);
}

interface ExpressionBaseVisTypeOptions extends CommonBaseVisTypeOptions {
toExpressionAst: VisToExpressionAst;
interface ExpressionBaseVisTypeOptions<TVisParams> extends CommonBaseVisTypeOptions {
toExpressionAst: VisToExpressionAst<TVisParams>;
visualization?: undefined;
}

Expand All @@ -53,9 +53,11 @@ interface VisualizationBaseVisTypeOptions extends CommonBaseVisTypeOptions {
visualization: VisualizationControllerConstructor | undefined;
}

export type BaseVisTypeOptions = ExpressionBaseVisTypeOptions | VisualizationBaseVisTypeOptions;
export type BaseVisTypeOptions<TVisParams = VisParams> =
| ExpressionBaseVisTypeOptions<TVisParams>
| VisualizationBaseVisTypeOptions;

export class BaseVisType {
export class BaseVisType<TVisParams = VisParams> {
name: string;
title: string;
description: string;
Expand All @@ -77,9 +79,9 @@ export class BaseVisType {
setup?: unknown;
useCustomNoDataScreen: boolean;
inspectorAdapters?: Adapters | (() => Adapters);
toExpressionAst?: VisToExpressionAst;
toExpressionAst?: VisToExpressionAst<TVisParams>;

constructor(opts: BaseVisTypeOptions) {
constructor(opts: BaseVisTypeOptions<TVisParams>) {
if (!opts.icon && !opts.image) {
throw new Error('vis_type must define its icon or image');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class TypesService {
* registers a visualization type
* @param config - visualization type definition
*/
createBaseVisualization: (config: BaseVisTypeOptions): void => {
createBaseVisualization: <TVisParams>(config: BaseVisTypeOptions<TVisParams>): void => {
const vis = new BaseVisType(config);
registerVisualization(() => vis);
},
Expand Down

0 comments on commit 91580f1

Please sign in to comment.