Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updates to fix ts errors in v4.9.5 upgrade #176114

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors in both these files are due to the use of onData$. I believe the problem is that onData$ is declared as a generic function with 2 parameters, see below.

export interface ExpressionRendererParams extends IExpressionLoaderParams {
debounce?: number;
expression: string | ExpressionAstExpression;
hasCustomErrorRenderer?: boolean;
onData$?<TData, TInspectorAdapters>(
data: TData,
adapters?: TInspectorAdapters,
partial?: boolean
): void;
onEvent?(event: ExpressionRendererEvent): void;
onRender$?(item: number): void;
/**
* An observable which can be used to re-run the expression without destroying the component
*/
reload$?: Observable<unknown>;
}

Then when used like in ReactExpressionRendererType, it locks in the generic types for both TData and TInspectorAdapters, see here...

export type ReactExpressionRendererType = React.ComponentType<ReactExpressionRendererProps>;
export type ExpressionRendererComponent = React.FC<ReactExpressionRendererProps>;

But in both usages we set these types to a different type and typescript throws an error similar to...

Type 'TInspectorAdapters' is not assignable to type 'Partial<DefaultInspectorAdapters>'

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"**/isomorphic-fetch/node-fetch": "^2.6.7",
"**/remark-parse/trim": "1.0.1",
"**/sharp": "0.32.6",
"**/typescript": "4.7.4",
"**/typescript": "4.9.5",
"globby/fast-glob": "^3.2.11"
},
"dependencies": {
Expand Down Expand Up @@ -1669,7 +1669,7 @@
"tree-kill": "^1.2.2",
"ts-morph": "^15.1.0",
"tsd": "^0.20.0",
"typescript": "4.7.4",
"typescript": "4.9.5",
"url-loader": "^2.2.0",
"val-loader": "^1.1.1",
"vinyl-fs": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class AnalyticsClient implements IAnalyticsClient {
this.optInConfig$.next(optInConfigInstance);
};

// @ts-expect-error upgrade typescript v4.9.5
public registerContextProvider = <Context>(contextProviderOpts: ContextProviderOpts<Context>) => {
this.contextService.registerContextProvider(contextProviderOpts);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ContextService {
public registerContextProvider<Context>({
name,
context$,
schema,
schema, // @ts-expect-error upgrade typescript v4.9.5
}: ContextProviderOpts<Context>) {
if (this.contextProvidersSubscriptions.has(name)) {
throw new Error(`Context provider with name '${name}' already registered`);
Expand Down Expand Up @@ -60,6 +60,7 @@ export class ContextService {
.subscribe((context) => {
// We store each context linked to the context provider so they can increase and reduce
// the number of fields they report without having left-overs in the global context.
// @ts-expect-error upgrade typescript v4.9.5
this.contextProvidersRegistry.set(name, context);

// For every context change, we rebuild the global context.
Expand Down
1 change: 1 addition & 0 deletions packages/analytics/client/src/analytics_client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface IAnalyticsClient {
*
* @track-adoption
*/
// @ts-expect-error upgrade typescript v4.9.5
registerContextProvider: <Context>(contextProviderOpts: ContextProviderOpts<Context>) => void;
/**
* Removes the context provider and stop enriching the events from its context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function WithServices<P>(Comp: ComponentType<P>, overrides: Partial<Servi
const services = getMockServices(overrides);
return (
<ContentEditorProvider {...services}>
{/* @ts-expect-error upgrade typescript v4.9.5*/}
<Comp {...props} />
</ContentEditorProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ export class RouteValidator<P = {}, Q = {}, B = {}> {
namespace?: string
): RouteValidationResultType<typeof validationRule> {
if (isConfigSchema(validationRule)) {
// @ts-expect-error upgrade typescript v4.9.5
return validationRule.validate(data, {}, namespace);
} else if (typeof validationRule === 'function') {
// @ts-expect-error upgrade typescript v4.9.5
return this.validateFunction(validationRule, data, namespace);
} else {
throw new ValidationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export async function createCookieSessionStorageFactory<T>(

return {
asScoped(request: KibanaRequest) {
// @ts-expect-error upgrade typescript v4.9.5
return new ScopedCookieSessionStorage<T>(log, server, ensureRawRequest(request));
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function checkIsPathExposed<T = unknown>(
// Traverse the path to see if it is exposed or not
const exposedConfig = descriptor[key as keyof ExposedToBrowserDescriptor<T>];
if (exposedConfig && typeof exposedConfig === 'object') {
// @ts-expect-error Type 'undefined' is not assignable to type 'ExposedToBrowserDescriptor<T>'
descriptor = exposedConfig;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const performBulkUpdate = async <T>(

const typeDefinition = registry.getType(type)!;
const updatedAttributes = mergeForUpdate({
// @ts-expect-error upgrade typescript v4.9.5
targetAttributes: {
...migrated!.attributes,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export const executeUpdate = async <T>(
// therefor we can safely process with the "standard" update sequence.

const updatedAttributes = mergeForUpdate({
// @ts-expect-error upgrade typescript v4.9.5
targetAttributes: {
...migrated!.attributes,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class Interval<TFields = Fields> {
map: (
timestamp: number,
index: number
// @ts-expect-error upgrade typescript v4.9.5
) => Serializable<TGeneratedFields> | Array<Serializable<TGeneratedFields>>
// @ts-expect-error upgrade typescript v4.9.5
): SynthtraceGenerator<TGeneratedFields> {
const timestamps = this.getTimestamps();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function getSerializeTransform<TFields = ApmFields>() {
push(this, nextEvents, nextCallback);
}
},
// @ts-expect-error upgrade typescript v4.9.5
write(chunk: Serializable<TFields>, encoding, callback) {
push(this, chunk.serialize(), callback);
},
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-apm-synthtrace/src/lib/utils/with_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { ApmSynthtraceEsClient, LogsSynthtraceEsClient } from '../../..';

export type SynthtraceEsClient = ApmSynthtraceEsClient | LogsSynthtraceEsClient;
export type SynthGenerator<TFields> =
// @ts-expect-error upgrade typescript v4.9.5
| SynthtraceGenerator<TFields>
// @ts-expect-error upgrade typescript v4.9.5
| Array<SynthtraceGenerator<TFields>>
| Readable;

Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ export type AggregateOf<

export type AggregateOfMap<TAggregationMap extends AggregationMap | undefined, TDocument> = {
[TAggregationName in keyof TAggregationMap]: Required<TAggregationMap>[TAggregationName] extends AggregationsAggregationContainer
? AggregateOf<TAggregationMap[TAggregationName], TDocument>
? // @ts-expect-error upgrade typescript v4.9.5
AggregateOf<TAggregationMap[TAggregationName], TDocument>
: never; // using never means we effectively ignore optional keys, using {} creates a union type of { ... } | {}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-io-ts-utils/src/to_json_schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const toJsonSchema = (type: t.Mixed): JSONSchema => {
case 'ArrayType':
return { type: 'array', items: toJsonSchema(type.type) };

// @ts-expect-error upgrade typescript v4.9.5
case 'BooleanType':
return { type: 'boolean' };

Expand All @@ -73,9 +74,11 @@ export const toJsonSchema = (type: t.Mixed): JSONSchema => {
case 'IntersectionType':
return { allOf: type.types.map(toJsonSchema) };

// @ts-expect-error upgrade typescript v4.9.5
case 'NumberType':
return { type: 'number' };

// @ts-expect-error upgrade typescript v4.9.5
case 'StringType':
return { type: 'string' };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/common/obj_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
const result: any = {};
for (const [key, value] of Object.entries(obj) as any) {
for (const [key, value] of Object.entries(obj as any) as any) {
if (!keys.includes(key)) {
result[key] = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('threat_mapping', () => {
field: 'field.one',
type: 'mapping',
value: 'field.one',
// @ts-expect-error upgrade typescript v4.9.5
extra: 'blah',
},
];
Expand Down Expand Up @@ -120,6 +121,7 @@ describe('threat_mapping', () => {
value: 'field.one',
},
],
// @ts-expect-error upgrade typescript v4.9.5
extra: 'invalid',
},
];
Expand All @@ -140,6 +142,7 @@ describe('threat_mapping', () => {
field: 'field.one',
type: 'mapping',
value: 'field.one',
// @ts-expect-error upgrade typescript v4.9.5
extra: 'blah',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { v4 as uuidv4 } from 'uuid';
*/
type NotArray<T> = T extends unknown[] ? never : T;
export const addIdToItem = <T>(item: NotArray<T>): T => {
// @ts-expect-error upgrade typescript v4.9.5
const maybeId: typeof item & { id?: string } = item;
if (maybeId.id != null) {
return item;
Expand All @@ -41,6 +42,7 @@ export const removeIdFromItem = <T>(
},
Exclude<keyof T, 'id'>
> => {
// @ts-expect-error upgrade typescript v4.9.5
const maybeId: typeof item & { id?: string } = item;
if (maybeId.id != null) {
const { id, ...noId } = maybeId;
Expand Down
5 changes: 2 additions & 3 deletions packages/kbn-server-route-repository/src/test_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ createServerRouteFactory<{}, { options: { tags: string[] } }>()({
});

// Public APIs should be versioned
// @ts-expect-error upgrade typescript v4.9.5
createServerRouteFactory<{}, { options: { tags: string[] } }>()({
// @ts-expect-error
endpoint: 'GET /api/endpoint_with_params',
options: {
// @ts-expect-error
tags: [],
},
// @ts-expect-error
// @ts-expect-error upgrade typescript v4.9.5
handler: async (resources) => {},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('createKibanaProgram', () => {
"fetch": Object {
"typeDescriptor": Object {
"locale": Object {
"kind": 150,
"kind": 152,
"type": "StringKeyword",
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-utility-types/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type DotKey<
TObject extends Record<string, any>,
TKey extends keyof TObject & string,
TPrefix extends string
> = TObject[TKey] extends Array<infer TValueType>
> = TObject[TKey] extends Array<infer TValueType> // @ts-ignore
? ToArray<DotObject<TValueType, `${TPrefix}${TKey}.`>>
: TObject[TKey] extends Record<string, any>
? DotObject<TObject[TKey], `${TPrefix}${TKey}.`>
Expand Down
8 changes: 6 additions & 2 deletions packages/shared-ux/router/impl/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ export const Routes = ({
if (React.isValidElement(child) && child.type === LegacyRoute) {
const path = replace(child?.props.path, match.url + '/', '');
const renderFunction =
// @ts-expect-error upgrade typescript v4.9.5
typeof child?.props.children === 'function'
? child?.props.children
: child?.props.render;
? // @ts-expect-error upgrade typescript v4.9.5
child?.props.children
: // @ts-expect-error upgrade typescript v4.9.5
child?.props.render;

return (
<Route
path={path}
element={
<>
<MatchPropagator />
{/* @ts-expect-error upgrade typescript v4.9.5*/}
{(child?.props?.component && <child.props.component />) ||
(renderFunction && renderFunction()) ||
children}
Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export type CustomRequestHandlerMock<T> = {
};

const createCustomRequestHandlerContextMock = <T>(contextParts: T): CustomRequestHandlerMock<T> => {
// @ts-expect-error upgrade typescript v4.9.5
const mock = Object.entries(contextParts).reduce(
(context, [key, value]) => {
// @ts-expect-error type matching from inferred types is hard
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/tasks/fetch_agent_versions_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const FetchAgentVersionsList: Task = {
const versionsList = await getAvailableVersions(log);
const AGENT_VERSION_BUILD_FILE = 'x-pack/plugins/fleet/target/agent_versions_list.json';

if (versionsList !== []) {
if (versionsList.length !== 0) {
log.info(`Writing versions list to ${AGENT_VERSION_BUILD_FILE}`);
await write(
build.resolvePath(AGENT_VERSION_BUILD_FILE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ x-pack/plugins/lens/public/datatable_visualization/expression.tsx kibana-app
x-pack/plugins/lens/public/datatable_visualization/index.ts kibana-app
x-pack/plugins/lens/public/datatable_visualization/visualization.test.tsx kibana-app
x-pack/plugins/lens/public/datatable_visualization/visualization.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/debounced_component.test.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/debounced_component.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/index.ts kibana-app
x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx kibana-app
x-pack/plugins/lens/public/drag_drop/drag_drop.tsx kibana-app
x-pack/plugins/lens/public/drag_drop/index.ts kibana-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { from } from 'rxjs';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';
import { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import { Datatable, DatatableColumn, TextAlignment } from '@kbn/expressions-plugin/common';
import { Render } from '@kbn/presentation-util-plugin/public/__stories__';
import { ColorMode, CustomPaletteState } from '@kbn/charts-plugin/common';
import { getFormatService } from '../__mocks__/format_service';
Expand Down Expand Up @@ -209,7 +209,11 @@ storiesOf('renderers/visMetric', module)
},
labels: {
show: false,
style: { spec: { fontSize: '60px', align: 'left' }, type: 'style', css: '' },
style: {
spec: { fontSize: '60px', textAlign: TextAlignment.LEFT },
type: 'style',
css: '',
},
position: LabelPosition.TOP,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ function hasAutoscaleProps<T>(props: T): props is T & AutoScaleProps {
return false;
}

function getWrappedComponentProps<T>(props: T) {
function getWrappedComponentProps<T>(props: T): T {
if (hasAutoscaleProps(props)) {
const { autoScaleParams, renderComplete, ...rest } = props;
return rest;
return {
...props,
autoScaleParams: undefined,
renderComplete: undefined,
};
}
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved

return props;
Expand Down Expand Up @@ -132,7 +135,7 @@ export function withAutoScale<T>(WrappedComponent: ComponentType<T>) {
: {}),
}}
>
<WrappedComponent {...(restProps as T)} />
<WrappedComponent {...restProps} />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function createComponentWithContext<Props = Record<string, any>>(
services: PropTypes.object,
};

// @ts-expect-error upgrade typescript v4.9.5
return shallow(<MyComponent {...props} />, {
context: {
services: mockedContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface EmbeddableFactory<
*/
readonly isEditable: () => Promise<boolean>;

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useFieldFromProps } from '../hooks';

export interface Props<T, FormType = FormData, I = T> {
path: string;
// @ts-expect-error upgrade typescript v4.9.5
config?: FieldConfig<T, FormType, I>;
defaultValue?: T;
component?: FunctionComponent<any>;
Expand Down
Loading
Loading