From 894ac3c11966f7aa262572a67ab10aafefc221dc Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 5 Mar 2024 12:49:17 -0700 Subject: [PATCH] clean up @ts-expect-error failures from typescript v4.9.5 upgrade (#177902) Closes https://github.com/elastic/kibana/issues/176099 Skipped canvas work to limit scope. Canvas changes did not meet definition of "critical bug fixes". --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../default_embeddable_factory_provider.ts | 4 ++-- .../public/lib/embeddables/embeddable_factory.ts | 4 ++-- .../embeddables/embeddable_factory_definition.ts | 3 ++- src/plugins/embeddable/public/types.ts | 3 ++- .../public/services/create/index.ts | 2 +- .../public/services/create/provider.tsx | 6 ++++-- .../public/services/create/providers_mediator.ts | 5 ++++- .../public/services/create/registry.tsx | 5 ++++- .../plugins/embeddable_enhanced/public/plugin.ts | 3 ++- x-pack/plugins/embeddable_enhanced/tsconfig.json | 1 + .../public/classes/sources/es_agg_source/index.ts | 1 + .../public/classes/sources/es_agg_source/types.ts | 9 ++++++++- .../public/classes/sources/es_source/es_source.ts | 15 +++++---------- .../vector/properties/dynamic_style_property.tsx | 3 +-- .../vector/properties/static_style_property.ts | 2 +- .../styles/vector/properties/style_property.ts | 2 +- .../public/classes/styles/vector/symbol_utils.tsx | 4 +++- x-pack/plugins/maps/public/lazy_wrapper.tsx | 3 +-- 18 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts index 50555601d4bca..d3382efd2dc0d 100644 --- a/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts +++ b/src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts @@ -7,7 +7,7 @@ */ import { SavedObjectAttributes } from '@kbn/core/public'; - +import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { IContainer } from '..'; import { EmbeddableFactory } from './embeddable_factory'; import { EmbeddableStateWithType } from '../../../common/types'; @@ -19,7 +19,7 @@ export const defaultEmbeddableFactoryProvider = < I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable = IEmbeddable, - T = SavedObjectAttributes + T extends FinderAttributes = SavedObjectAttributes >( def: EmbeddableFactoryDefinition ): EmbeddableFactory => { diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts index cb777aecb53b8..cb19b82d75c98 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts @@ -8,6 +8,7 @@ import type { SavedObjectMetaData } from '@kbn/saved-objects-finder-plugin/public'; import { PersistableState } from '@kbn/kibana-utils-plugin/common'; +import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { UiActionsPresentableGrouping } from '@kbn/ui-actions-plugin/public'; import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; import { ErrorEmbeddable } from './error_embeddable'; @@ -45,7 +46,7 @@ export interface EmbeddableFactory< TEmbeddableInput, TEmbeddableOutput >, - TSavedObjectAttributes = unknown + TSavedObjectAttributes extends FinderAttributes = FinderAttributes > extends PersistableState { /** * The version of this Embeddable factory. This will be used in the client side migration system @@ -65,7 +66,6 @@ export interface EmbeddableFactory< */ readonly isEditable: () => Promise; - // @ts-expect-error upgrade typescript v4.9.5 readonly savedObjectMetaData?: SavedObjectMetaData; /** diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts index 4c360ffd40eb5..66e0f7f0db3eb 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable_factory_definition.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { IEmbeddable } from './i_embeddable'; import { EmbeddableFactory } from './embeddable_factory'; import { EmbeddableInput, EmbeddableOutput } from '..'; @@ -14,7 +15,7 @@ export type EmbeddableFactoryDefinition< I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable = IEmbeddable, - T = unknown + T extends FinderAttributes = FinderAttributes > = // Required parameters Pick< diff --git a/src/plugins/embeddable/public/types.ts b/src/plugins/embeddable/public/types.ts index 7f24f525ae49f..a4f3aa97e55cc 100644 --- a/src/plugins/embeddable/public/types.ts +++ b/src/plugins/embeddable/public/types.ts @@ -8,6 +8,7 @@ import type { SerializableRecord } from '@kbn/utility-types'; import { SavedObjectAttributes } from '@kbn/core/public'; +import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { PersistableState, PersistableStateDefinition } from '@kbn/kibana-utils-plugin/common'; import { EmbeddableFactory, @@ -34,7 +35,7 @@ export type EmbeddableFactoryProvider = < I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable = IEmbeddable, - T = SavedObjectAttributes + T extends FinderAttributes = SavedObjectAttributes >( def: EmbeddableFactoryDefinition ) => EmbeddableFactory; diff --git a/src/plugins/presentation_util/public/services/create/index.ts b/src/plugins/presentation_util/public/services/create/index.ts index d616d7bee20c8..32b3638f1a623 100644 --- a/src/plugins/presentation_util/public/services/create/index.ts +++ b/src/plugins/presentation_util/public/services/create/index.ts @@ -27,7 +27,7 @@ type ServiceHooks = { [K in keyof Services]: { useService: () => Servi * * The `Services` generic determines the shape of all service APIs being produced. */ -export class PluginServices { +export class PluginServices> { private registry: PluginServiceRegistry | null = null; /** diff --git a/src/plugins/presentation_util/public/services/create/provider.tsx b/src/plugins/presentation_util/public/services/create/provider.tsx index c95231c6826d6..0cebcce5e9572 100644 --- a/src/plugins/presentation_util/public/services/create/provider.tsx +++ b/src/plugins/presentation_util/public/services/create/provider.tsx @@ -16,9 +16,11 @@ import { PluginServiceFactory } from './factory'; * The `StartParameters` generic determines what parameters are expected to * start the service. */ -export type PluginServiceProviders = { +export type PluginServiceProviders< + Services extends Record, + StartParameters = {} +> = { [K in keyof Services]: PluginServiceProvider< - // @ts-expect-error upgrade typescript v4.9.5 Services[K], StartParameters, Services, diff --git a/src/plugins/presentation_util/public/services/create/providers_mediator.ts b/src/plugins/presentation_util/public/services/create/providers_mediator.ts index dd5937149850c..f7ffce71338c3 100644 --- a/src/plugins/presentation_util/public/services/create/providers_mediator.ts +++ b/src/plugins/presentation_util/public/services/create/providers_mediator.ts @@ -9,7 +9,10 @@ import { DependencyManager } from './dependency_manager'; import { PluginServiceProviders, PluginServiceRequiredServices } from './provider'; -export class PluginServiceProvidersMediator { +export class PluginServiceProvidersMediator< + Services extends Record, + StartParameters +> { constructor(private readonly providers: PluginServiceProviders) {} start(params: StartParameters) { diff --git a/src/plugins/presentation_util/public/services/create/registry.tsx b/src/plugins/presentation_util/public/services/create/registry.tsx index 8369815a042af..056822408f8be 100644 --- a/src/plugins/presentation_util/public/services/create/registry.tsx +++ b/src/plugins/presentation_util/public/services/create/registry.tsx @@ -18,7 +18,10 @@ import { PluginServiceProvidersMediator } from './providers_mediator'; * The `StartParameters` generic determines what parameters are expected to * start the service. */ -export class PluginServiceRegistry { +export class PluginServiceRegistry< + Services extends Record, + StartParameters = {} +> { private providers: PluginServiceProviders; private providersMediator: PluginServiceProvidersMediator; private _isStarted = false; diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index ed829a9326e9e..b46390d529c23 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -23,6 +23,7 @@ import { AdvancedUiActionsSetup, AdvancedUiActionsStart, } from '@kbn/ui-actions-enhanced-plugin/public'; +import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { EnhancedEmbeddable } from './types'; import { EmbeddableActionStorage, @@ -76,7 +77,7 @@ export class EmbeddableEnhancedPlugin I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable = IEmbeddable, - T = unknown + T extends FinderAttributes = {} >( def: EmbeddableFactoryDefinition ): EmbeddableFactory => { diff --git a/x-pack/plugins/embeddable_enhanced/tsconfig.json b/x-pack/plugins/embeddable_enhanced/tsconfig.json index 6a3face73f9ca..2c7f1c5d23270 100644 --- a/x-pack/plugins/embeddable_enhanced/tsconfig.json +++ b/x-pack/plugins/embeddable_enhanced/tsconfig.json @@ -15,6 +15,7 @@ "@kbn/kibana-utils-plugin", "@kbn/data-plugin", "@kbn/utility-types", + "@kbn/saved-objects-finder-plugin", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/maps/public/classes/sources/es_agg_source/index.ts b/x-pack/plugins/maps/public/classes/sources/es_agg_source/index.ts index 9f262ac02648e..09fa1a70c843b 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_agg_source/index.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_agg_source/index.ts @@ -6,5 +6,6 @@ */ export type { IESAggSource, ESAggsSourceSyncMeta } from './types'; +export { hasESAggSourceMethod } from './types'; export { AbstractESAggSource, DEFAULT_METRIC } from './es_agg_source'; export { getAggDisplayName } from './get_agg_display_name'; diff --git a/x-pack/plugins/maps/public/classes/sources/es_agg_source/types.ts b/x-pack/plugins/maps/public/classes/sources/es_agg_source/types.ts index 6f758c505fd89..7d31f07b9ab53 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_agg_source/types.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_agg_source/types.ts @@ -7,9 +7,16 @@ import { DataView } from '@kbn/data-plugin/common'; import { AGG_TYPE } from '../../../../common/constants'; -import type { IESSource } from '../es_source'; +import type { IESSource } from '../es_source/types'; import { IESAggField } from '../../fields/agg'; +export function hasESAggSourceMethod( + source: IESSource, + methodName: keyof IESAggSource +): source is Pick { + return typeof (source as IESAggSource)[methodName] === 'function'; +} + export interface IESAggSource extends IESSource { getAggKey(aggType: AGG_TYPE, fieldName: string): string; getAggLabel(aggType: AGG_TYPE, fieldLabel: string): Promise; diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index 0e5a48b3d5827..23b82159a4bae 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -16,7 +16,7 @@ import { RequestAdapter } from '@kbn/inspector-plugin/common/adapters/request'; import { lastValueFrom } from 'rxjs'; import type { TimeRange } from '@kbn/es-query'; import { extractWarnings, type SearchResponseWarning } from '@kbn/search-response-warnings'; -import type { IESAggSource } from '../es_agg_source'; +import { hasESAggSourceMethod } from '../es_agg_source/types'; import { AbstractVectorSource, BoundsRequestMeta } from '../vector_source'; import { getAutocompleteService, @@ -183,15 +183,10 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource // buffer can be empty const geoField = await this._getGeoField(); const buffer: MapExtent = - 'isGeoGridPrecisionAware' in this && - 'getGeoGridPrecision' in this && - // @ts-expect-error upgrade typescript v4.9.5 - (this as IESAggSource).isGeoGridPrecisionAware() - ? expandToTileBoundaries( - requestMeta.buffer, - // @ts-expect-error upgrade typescript v4.9.5 - (this as IESAggSource).getGeoGridPrecision(requestMeta.zoom) - ) + hasESAggSourceMethod(this, 'isGeoGridPrecisionAware') && + hasESAggSourceMethod(this, 'getGeoGridPrecision') && + this.isGeoGridPrecisionAware() + ? expandToTileBoundaries(requestMeta.buffer, this.getGeoGridPrecision(requestMeta.zoom)) : requestMeta.buffer; const extentFilter = createExtentFilter(buffer, [geoField.name]); diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx index 72a930553f4ec..c69e4d855ad90 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx @@ -99,7 +99,7 @@ export interface IDynamicStyleProperty extends IStyleProperty { ): boolean; } -export class DynamicStyleProperty +export class DynamicStyleProperty extends AbstractStyleProperty implements IDynamicStyleProperty { @@ -350,7 +350,6 @@ export class DynamicStyleProperty } getDataMappingFunction() { - // @ts-expect-error upgrade typescript v4.9.5 return 'dataMappingFunction' in this._options ? (this._options as T & { dataMappingFunction: DATA_MAPPING_FUNCTION }).dataMappingFunction : DATA_MAPPING_FUNCTION.INTERPOLATE; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/static_style_property.ts b/x-pack/plugins/maps/public/classes/styles/vector/properties/static_style_property.ts index ed09d35235eda..aad248ecc2033 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/static_style_property.ts +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/static_style_property.ts @@ -8,6 +8,6 @@ import { AbstractStyleProperty } from './style_property'; import { STYLE_TYPE } from '../../../../../common/constants'; -export class StaticStyleProperty extends AbstractStyleProperty { +export class StaticStyleProperty extends AbstractStyleProperty { static type = STYLE_TYPE.STATIC; } diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/style_property.ts b/x-pack/plugins/maps/public/classes/styles/vector/properties/style_property.ts index ee3da4e3636b3..3de004690e3e7 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/style_property.ts +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/style_property.ts @@ -32,7 +32,7 @@ export interface IStyleProperty { getDisplayStyleName(): string; } -export class AbstractStyleProperty implements IStyleProperty { +export class AbstractStyleProperty implements IStyleProperty { protected readonly _options: T; protected readonly _styleName: VECTOR_STYLES; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/symbol_utils.tsx b/x-pack/plugins/maps/public/classes/styles/vector/symbol_utils.tsx index a0a2b27abb2f4..4f70524751b63 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/symbol_utils.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/symbol_utils.tsx @@ -59,7 +59,9 @@ export async function createSdfIcon({ svgCanvas.width = size; svgCanvas.height = size; const svgCtx = svgCanvas.getContext('2d'); - // @ts-expect-error upgrade typescript v4.9.5 + if (!svgCtx) { + return null; + } const v = Canvg.fromString(svgCtx, svg, { ignoreDimensions: true, offsetX: buffer / 2, diff --git a/x-pack/plugins/maps/public/lazy_wrapper.tsx b/x-pack/plugins/maps/public/lazy_wrapper.tsx index 184cbc310da46..6444237e82f36 100644 --- a/x-pack/plugins/maps/public/lazy_wrapper.tsx +++ b/x-pack/plugins/maps/public/lazy_wrapper.tsx @@ -16,7 +16,7 @@ const Fallback = () => ( interface Props { getLazyComponent: () => FC; - lazyComponentProps: T; + lazyComponentProps: JSX.IntrinsicAttributes & T; } export function LazyWrapper({ getLazyComponent, lazyComponentProps }: Props) { @@ -24,7 +24,6 @@ export function LazyWrapper({ getLazyComponent, lazyComponentProps }: Props }> - {/* @ts-expect-error upgrade typescript v4.9.5*/}