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(NA): upgrade typescript into v4.9.5 #175178

Merged
merged 35 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
db71d4b
chore(NA): upgrade typescript into v4.9.5
mistic Jan 19, 2024
28f8564
chore(NA): added expected errors annotations across the failing types
mistic Jan 20, 2024
39606d9
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 20, 2024
62a64f1
fix(NA): linting and failing types
mistic Jan 20, 2024
a94b29c
Merge branch 'upgrade-typescript-v4-9-5' of github.com:mistic/kibana …
mistic Jan 20, 2024
5a1eda0
fix(NA): failing types
mistic Jan 20, 2024
555d388
fix(NA): failing types
mistic Jan 20, 2024
e5c0297
test(NA): fix unit snapshot
mistic Jan 21, 2024
9da1d8e
Merge remote-tracking branch 'upstream/main' into upgrade-typescript-…
mistic Jan 21, 2024
5eef5bb
chore(NA): merge and solve conflicts with main
mistic Feb 1, 2024
7e6e66f
chore(NA): adding missing expect error statement
mistic Feb 1, 2024
0c669ff
chore: updates to fix most ts errors in `v4.9.5` upgrade (#18)
nickofthyme Feb 2, 2024
6b3b4d6
fix: use `DeepMap<Values, string>` instead of `Result` in src/plugins…
azasypkin Feb 6, 2024
dce9849
Merge branch 'main' into upgrade-typescript-v4-9-5
mistic Feb 7, 2024
19dbfa3
Merge branch 'main' into upgrade-typescript-v4-9-5
mistic Feb 7, 2024
bcd925e
chore(NA): missing expect error after sync with upstream
mistic Feb 7, 2024
6e8c785
chore(NA): merge and solve conflicts with main
mistic Feb 8, 2024
d086abe
Merge remote-tracking branch 'upstream/main' into upgrade-typescript-…
mistic Feb 8, 2024
c3b496b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 8, 2024
917aa9f
Merge branch 'main' into upgrade-typescript-v4-9-5
mistic Feb 9, 2024
273db7c
Fix typescript errors
dgieselaar Feb 13, 2024
6f6c212
Fix logs shared and a bit of synthtrace
achyutjhunjhunwala Feb 13, 2024
168d797
fix one missing type fix for Logs
achyutjhunjhunwala Feb 13, 2024
a8c418d
revert fix for logs_shared
achyutjhunjhunwala Feb 13, 2024
48bd988
Fix Synthetics TypeScript errors where practicable.
justinkambic Feb 13, 2024
8789f21
Merge branch 'main' into upgrade-typescript-v4-9-5
mistic Feb 16, 2024
177f8c9
fix TS errors in `stringEnum` utility type
janmonschke Feb 19, 2024
bbcd5d5
Merge remote-tracking branch 'upstream/main' into upgrade-typescript-…
mistic Feb 23, 2024
3a8ba61
Merge remote-tracking branch 'upstream/main' into upgrade-typescript-…
mistic Feb 23, 2024
e9fe384
fix(NA): missing ts expect error
mistic Feb 23, 2024
6b2512c
fix(NA): remove unused ts expect error
mistic Feb 23, 2024
3411e28
Merge branch 'main' into upgrade-typescript-v4-9-5
mistic Feb 24, 2024
c44e462
fix(NA): unit tests
mistic Feb 24, 2024
8b3f482
Merge branch 'upgrade-typescript-v4-9-5' of github.com:mistic/kibana …
mistic Feb 24, 2024
3d270ad
Merge remote-tracking branch 'upstream/main' into upgrade-typescript-…
mistic Feb 24, 2024
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
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 @@ -1677,7 +1677,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 @@ -168,6 +168,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
4 changes: 2 additions & 2 deletions packages/kbn-apm-synthtrace-client/src/lib/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface IntervalOptions {
rate?: number;
}

export class Interval<TFields = Fields> {
export class Interval<TFields extends Fields = Fields> {
private readonly intervalAmount: number;
private readonly intervalUnit: unitOfTime.DurationConstructor;

Expand Down Expand Up @@ -63,7 +63,7 @@ export class Interval<TFields = Fields> {
return timestamps;
}

*generator<TGeneratedFields = TFields>(
*generator<TGeneratedFields extends Fields = TFields>(
map: (
timestamp: number,
index: number
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 not sure how to fix this, anything I've tried causes errors upstream - Dario
AggregateOf<TAggregationMap[TAggregationName], TDocument>
: never; // using never means we effectively ignore optional keys, using {} creates a union type of { ... } | {}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-io-ts-utils/src/to_json_schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import * as t from 'io-ts';
import { mapValues } from 'lodash';
import { isParsableType } from '../parseable_types';
import { isParsableType, ParseableType } from '../parseable_types';

interface JSONSchemaObject {
type: 'object';
Expand Down Expand Up @@ -45,7 +45,7 @@ type JSONSchema =
| JSONSchemaAllOf
| JSONSchemaAnyOf;

export const toJsonSchema = (type: t.Mixed): JSONSchema => {
export const toJsonSchema = (type: t.Type<any> | ParseableType): JSONSchema => {
if (isParsableType(type)) {
switch (type._tag) {
case 'ArrayType':
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
3 changes: 1 addition & 2 deletions packages/kbn-server-route-repository/src/test_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ createServerRouteFactory<{}, { options: { tags: string[] } }>()({
});

// Public APIs should be versioned
// @ts-expect-error
createServerRouteFactory<{}, { options: { tags: string[] } }>()({
// @ts-expect-error
endpoint: 'GET /api/endpoint_with_params',
options: {
// @ts-expect-error
tags: [],
},
// @ts-expect-error
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
4 changes: 3 additions & 1 deletion packages/kbn-utility-types/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ type DotKey<
TKey extends keyof TObject & string,
TPrefix extends string
> = TObject[TKey] extends Array<infer TValueType>
? ToArray<DotObject<TValueType, `${TPrefix}${TKey}.`>>
? TValueType extends Record<string, any>
? ToArray<DotObject<TValueType, `${TPrefix}${TKey}.`>>
: never
: TObject[TKey] extends Record<string, any>
? DotObject<TObject[TKey], `${TPrefix}${TKey}.`>
: { [key in `${TPrefix}${TKey}`]: TObject[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 @@ -143,6 +143,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,
};
}

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 @@ -9,6 +9,7 @@
import { SavedObjectCommon } from '@kbn/saved-objects-finder-plugin/common';

type SavedObjectToPanelMethod<TSavedObjectAttributes, TByValueInput> = (
// @ts-expect-error upgrade typescript v4.9.5
savedObject: SavedObjectCommon<TSavedObjectAttributes>
) => { savedObjectId: string } | Partial<TByValueInput>;

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