Skip to content

Commit

Permalink
clean up @ts-expect-error failures from typescript v4.9.5 upgrade (#1…
Browse files Browse the repository at this point in the history
…77902)

Closes #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>
nreese and kibanamachine authored Mar 5, 2024
1 parent 555b7b6 commit 894ac3c
Showing 18 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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<I, O> = IEmbeddable<I, O>,
T = SavedObjectAttributes
T extends FinderAttributes = SavedObjectAttributes
>(
def: EmbeddableFactoryDefinition<I, O, E, T>
): EmbeddableFactory<I, O, E, T> => {
Original file line number Diff line number Diff line change
@@ -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<EmbeddableStateWithType> {
/**
* 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<boolean>;

// @ts-expect-error upgrade typescript v4.9.5
readonly savedObjectMetaData?: SavedObjectMetaData<TSavedObjectAttributes>;

/**
Original file line number Diff line number Diff line change
@@ -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<I, O> = IEmbeddable<I, O>,
T = unknown
T extends FinderAttributes = FinderAttributes
> =
// Required parameters
Pick<
3 changes: 2 additions & 1 deletion src/plugins/embeddable/public/types.ts
Original file line number Diff line number Diff line change
@@ -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<I, O> = IEmbeddable<I, O>,
T = SavedObjectAttributes
T extends FinderAttributes = SavedObjectAttributes
>(
def: EmbeddableFactoryDefinition<I, O, E, T>
) => EmbeddableFactory<I, O, E, T>;
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ type ServiceHooks<Services> = { [K in keyof Services]: { useService: () => Servi
*
* The `Services` generic determines the shape of all service APIs being produced.
*/
export class PluginServices<Services> {
export class PluginServices<Services extends Record<keyof Services, {}>> {
private registry: PluginServiceRegistry<Services, any> | null = null;

/**
Original file line number Diff line number Diff line change
@@ -16,9 +16,11 @@ import { PluginServiceFactory } from './factory';
* The `StartParameters` generic determines what parameters are expected to
* start the service.
*/
export type PluginServiceProviders<Services, StartParameters = {}> = {
export type PluginServiceProviders<
Services extends Record<keyof Services, {}>,
StartParameters = {}
> = {
[K in keyof Services]: PluginServiceProvider<
// @ts-expect-error upgrade typescript v4.9.5
Services[K],
StartParameters,
Services,
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@
import { DependencyManager } from './dependency_manager';
import { PluginServiceProviders, PluginServiceRequiredServices } from './provider';

export class PluginServiceProvidersMediator<Services, StartParameters> {
export class PluginServiceProvidersMediator<
Services extends Record<keyof Services, {}>,
StartParameters
> {
constructor(private readonly providers: PluginServiceProviders<Services, StartParameters>) {}

start(params: StartParameters) {
Original file line number Diff line number Diff line change
@@ -18,7 +18,10 @@ import { PluginServiceProvidersMediator } from './providers_mediator';
* The `StartParameters` generic determines what parameters are expected to
* start the service.
*/
export class PluginServiceRegistry<Services, StartParameters = {}> {
export class PluginServiceRegistry<
Services extends Record<keyof Services, {}>,
StartParameters = {}
> {
private providers: PluginServiceProviders<Services, StartParameters>;
private providersMediator: PluginServiceProvidersMediator<Services, StartParameters>;
private _isStarted = false;
3 changes: 2 additions & 1 deletion x-pack/plugins/embeddable_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -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<I, O> = IEmbeddable<I, O>,
T = unknown
T extends FinderAttributes = {}
>(
def: EmbeddableFactoryDefinition<I, O, E, T>
): EmbeddableFactory<I, O, E, T> => {
1 change: 1 addition & 0 deletions x-pack/plugins/embeddable_enhanced/tsconfig.json
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
"@kbn/kibana-utils-plugin",
"@kbn/data-plugin",
"@kbn/utility-types",
"@kbn/saved-objects-finder-plugin",
],
"exclude": [
"target/**/*",
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<IESAggSource, typeof methodName> {
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<string>;
15 changes: 5 additions & 10 deletions x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts
Original file line number Diff line number Diff line change
@@ -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]);

Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ export interface IDynamicStyleProperty<T> extends IStyleProperty<T> {
): boolean;
}

export class DynamicStyleProperty<T>
export class DynamicStyleProperty<T extends object>
extends AbstractStyleProperty<T>
implements IDynamicStyleProperty<T>
{
@@ -350,7 +350,6 @@ export class DynamicStyleProperty<T>
}

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;
Original file line number Diff line number Diff line change
@@ -8,6 +8,6 @@
import { AbstractStyleProperty } from './style_property';
import { STYLE_TYPE } from '../../../../../common/constants';

export class StaticStyleProperty<T> extends AbstractStyleProperty<T> {
export class StaticStyleProperty<T extends object> extends AbstractStyleProperty<T> {
static type = STYLE_TYPE.STATIC;
}
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ export interface IStyleProperty<T> {
getDisplayStyleName(): string;
}

export class AbstractStyleProperty<T> implements IStyleProperty<T> {
export class AbstractStyleProperty<T extends object> implements IStyleProperty<T> {
protected readonly _options: T;
protected readonly _styleName: VECTOR_STYLES;

Original file line number Diff line number Diff line change
@@ -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,
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/public/lazy_wrapper.tsx
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ const Fallback = () => (

interface Props<T> {
getLazyComponent: () => FC<T>;
lazyComponentProps: T;
lazyComponentProps: JSX.IntrinsicAttributes & T;
}

export function LazyWrapper<T>({ getLazyComponent, lazyComponentProps }: Props<T>) {
const LazyComponent = getLazyComponent();
return (
<EuiErrorBoundary>
<Suspense fallback={<Fallback />}>
{/* @ts-expect-error upgrade typescript v4.9.5*/}
<LazyComponent {...lazyComponentProps} />
</Suspense>
</EuiErrorBoundary>

0 comments on commit 894ac3c

Please sign in to comment.