From 7ccd6e1b6a5e4724011e7d7bb88b16aa1cc20176 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Tue, 7 Apr 2020 18:54:06 -0400 Subject: [PATCH] Fix type issues --- x-pack/legacy/plugins/lens/migrations.test.ts | 13 +++++---- x-pack/legacy/plugins/lens/migrations.ts | 28 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/x-pack/legacy/plugins/lens/migrations.test.ts b/x-pack/legacy/plugins/lens/migrations.test.ts index 90d1cac10416c..7e9dd36bca1f5 100644 --- a/x-pack/legacy/plugins/lens/migrations.test.ts +++ b/x-pack/legacy/plugins/lens/migrations.test.ts @@ -4,13 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { migrations } from './migrations'; +import { migrations, RawLensSavedXYObject770 } from './migrations'; +import { SimpleSavedObject } from 'src/core/public'; describe('Lens migrations', () => { describe('7.7.0 missing dimensions in XY', () => { - const migrate = (doc: unknown) => migrations['7.7.0'](doc); + const migrate = (doc: SimpleSavedObject | RawLensSavedXYObject770) => migrations['7.7.0'](doc); - const example = { + const example: RawLensSavedXYObject770 = { type: 'lens', attributes: { expression: @@ -105,7 +106,7 @@ describe('Lens migrations', () => { visualizationType: 'lnsMetric', }, }; - const result = migrate(target); + const result = migrate(target as SimpleSavedObject); expect(result).toEqual(target); }); @@ -123,7 +124,7 @@ describe('Lens migrations', () => { }, }, }, - }); + } as SimpleSavedObject) as RawLensSavedXYObject770; expect(result.attributes.state.visualization.layers).toEqual([ { @@ -139,7 +140,7 @@ describe('Lens migrations', () => { }); it('should remove only missing accessors', () => { - const result = migrate(example); + const result = migrate(example) as RawLensSavedXYObject770; expect(result.attributes.state.visualization.layers).toEqual([ { diff --git a/x-pack/legacy/plugins/lens/migrations.ts b/x-pack/legacy/plugins/lens/migrations.ts index 30eced3074eba..14b41b3af537c 100644 --- a/x-pack/legacy/plugins/lens/migrations.ts +++ b/x-pack/legacy/plugins/lens/migrations.ts @@ -7,23 +7,25 @@ import { cloneDeep } from 'lodash'; import { SimpleSavedObject } from 'src/core/public'; -interface RawLensSavedXYObject770 { +export interface RawLensSavedXYObject770 { type: 'lens'; - attributes: { + attributes: Record & { visualizationType: string; - state: { - datasourceStates?: { - indexpattern?: { - layers: Record }>; + state: Record & { + datasourceStates?: Record & { + indexpattern?: Record & { + layers: Record & { columns: Record }>; }; }; - visualization: { - layers: Array<{ - layerId: string; - accessors: string[]; - xAccessor: string; - splitAccessor: string; - }>; + visualization: Record & { + layers: Array< + Record & { + layerId: string; + accessors: string[]; + xAccessor: string; + splitAccessor: string; + } + >; }; }; };