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

[7.x] Upgrade to TypeScript 3.7.2 (#47188) #50756

Merged
merged 2 commits into from
Nov 15, 2019
Merged
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
1 change: 1 addition & 0 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ You should prefer modern language features in a lot of cases, e.g.:
* Prefer arrow function over storing `this` (no `const self = this;`)
* Prefer template strings over string concatenation
* Prefer the spread operator for copying arrays (`[...arr]`) over `arr.slice()`
* Use optional chaining (`?.`) and nullish Coalescing (`??`) over `lodash.get` (and similar utilities)

### Avoid mutability and state

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"**/@types/react": "16.8.3",
"**/@types/hapi": "^17.0.18",
"**/@types/angular": "^1.6.56",
"**/typescript": "3.5.3",
"**/typescript": "3.7.2",
"**/graphql-toolkit/lodash": "^4.17.13",
"**/isomorphic-git/**/base64-js": "^1.2.1",
"**/image-diff/gm/debug": "^2.6.9"
Expand Down Expand Up @@ -342,8 +342,8 @@
"@types/uuid": "^3.4.4",
"@types/vinyl-fs": "^2.4.11",
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"angular-mocks": "^1.7.8",
"archiver": "^3.1.1",
"babel-eslint": "^10.0.3",
Expand Down Expand Up @@ -438,7 +438,7 @@
"supertest": "^3.1.0",
"supertest-as-promised": "^4.0.2",
"tree-kill": "^1.2.1",
"typescript": "3.5.3",
"typescript": "3.7.2",
"typings-tester": "^0.3.2",
"vinyl-fs": "^3.0.3",
"xml2js": "^0.4.22",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-kibana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"homepage": "https://github.com/elastic/eslint-config-kibana#readme",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.5.1",
"eslint-plugin-babel": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@babel/cli": "7.5.5",
"@kbn/dev-utils": "1.0.0",
"@kbn/babel-preset": "1.0.0",
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/kbn-config-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"kbn:bootstrap": "yarn build"
},
"devDependencies": {
"typescript": "3.5.3"
"typescript": "3.7.2"
},
"peerDependencies": {
"joi": "^13.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"typescript": "3.5.3",
"typescript": "3.7.2",
"@kbn/expect": "1.0.0",
"chance": "1.0.18"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-elastic-idx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/core": "^7.5.5",
"@babel/plugin-transform-async-to-generator": "^7.5.0",
"jest": "^24.9.0",
"typescript": "3.5.3"
"typescript": "3.7.2"
},
"jest": {
"testEnvironment": "node"
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"del": "^5.1.0",
"getopts": "^2.2.4",
"supports-color": "^6.1.0",
"typescript": "3.5.3"
"typescript": "3.7.2"
},
"dependencies": {
"intl-format-cache": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-pm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"strip-ansi": "^4.0.0",
"strong-log-transformer": "^2.1.0",
"tempy": "^0.3.0",
"typescript": "3.5.3",
"typescript": "3.7.2",
"unlazy-loader": "^0.1.3",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9",
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/console/server/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import http from 'http';
import http, { ClientRequest } from 'http';
import * as sinon from 'sinon';
import { sendRequest } from './request';
import { URL } from 'url';
import { fail } from 'assert';

describe(`Console's send request`, () => {
let sandbox: sinon.SinonSandbox;
let stub: sinon.SinonStub;
let stub: sinon.SinonStub<Parameters<typeof http['request']>, ClientRequest>;
let fakeRequest: http.ClientRequest;

beforeEach(() => {
Expand Down
19 changes: 11 additions & 8 deletions src/legacy/core_plugins/tile_map/public/components/wms_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { TmsLayer } from 'ui/vis/map/service_settings';
import { Vis } from 'ui/vis';
import { RegionMapVisParams } from '../../../region_map/public/types';
import { SelectOption, SwitchOption } from '../../../kbn_vislib_vis_types/public/components';
import { RegionMapOptionsProps } from '../../../region_map/public/components/region_map_options';
import { WmsInternalOptions } from './wms_internal_options';
import { TileMapOptionsProps } from './tile_map_options';
import { TileMapVisParams } from '../types';
import { WMSOptions, TileMapVisParams } from '../types';

interface Props {
stateParams: TileMapVisParams | RegionMapVisParams;
setValue: (title: 'wms', options: WMSOptions) => void;
vis: Vis;
}

const mapLayerForOption = ({ id }: TmsLayer) => ({ text: id, value: id });

function WmsOptions({ stateParams, setValue, vis }: TileMapOptionsProps | RegionMapOptionsProps) {
function WmsOptions({ stateParams, setValue, vis }: Props) {
const { wms } = stateParams;
const { tmsLayers } = vis.type.editorConfig.collections;
const tmsLayerOptions = useMemo(() => tmsLayers.map(mapLayerForOption), [tmsLayers]);

const setWmsOption = <T extends keyof TileMapVisParams['wms']>(
paramName: T,
value: TileMapVisParams['wms'][T]
) =>
const setWmsOption = <T extends keyof WMSOptions>(paramName: T, value: WMSOptions[T]) =>
setValue('wms', {
...wms,
[paramName]: value,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/expressions/public/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { ExpressionInterpret } from '../interpreter_provider';
import { TimeRange } from '../../../data/public';
import { Adapters } from '../../../inspector/public';
import { Query } from '../../../data/public';
import { ExpressionAST } from '../../../expressions/public';
import { ExpressionArgAST } from '../../../../plugins/expressions/public';
import { esFilters } from '../../../../plugins/data/public';

export { ArgumentType } from './arguments';
Expand Down
2 changes: 1 addition & 1 deletion test/plugin_functional/plugins/core_plugin_a/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
2 changes: 1 addition & 1 deletion test/plugin_functional/plugins/core_plugin_b/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"devDependencies": {
"@kbn/plugin-helpers": "9.0.2",
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"devDependencies": {
"@kbn/plugin-helpers": "9.0.2",
"typescript": "3.5.3"
"typescript": "3.7.2"
}
}
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/apm/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"@cypress/snapshot": "^2.1.3",
"@cypress/webpack-preprocessor": "^4.1.0",
"@types/js-yaml": "^3.12.1",
"cypress": "^3.4.1",
"cypress": "^3.5.0",
"js-yaml": "^3.13.1",
"p-limit": "^2.2.1",
"ts-loader": "^6.1.0",
"typescript": "^3.6.3",
"typescript": "3.7.2",
"webpack": "^4.40.2"
}
}
24 changes: 20 additions & 4 deletions x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
import { Legacy } from 'kibana';
import { Server } from 'hapi';
import moment from 'moment';
import { KibanaConfig } from 'src/legacy/server/kbn_server';
import { getESClient } from './es_client';
import { getUiFiltersES } from './convert_ui_filters/get_ui_filters_es';
import { PromiseReturnType } from '../../../typings/common';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import {
getApmIndices,
ApmIndicesConfig
} from '../settings/apm_indices/get_apm_indices';
import { ESFilter } from '../../../typings/elasticsearch';
import { ESClient } from './es_client';

function decodeUiFilters(server: Server, uiFiltersEncoded?: string) {
if (!uiFiltersEncoded) {
Expand All @@ -26,9 +31,20 @@ export interface APMRequestQuery {
end?: string;
uiFilters?: string;
}
// Explicitly type Setup to prevent TS initialization errors
// https://github.com/microsoft/TypeScript/issues/34933

export type Setup = PromiseReturnType<typeof setupRequest>;
export async function setupRequest(req: Legacy.Request) {
export interface Setup {
start: number;
end: number;
uiFiltersES: ESFilter[];
client: ESClient;
internalClient: ESClient;
config: KibanaConfig;
indices: ApmIndicesConfig;
}

export async function setupRequest(req: Legacy.Request): Promise<Setup> {
const query = (req.query as unknown) as APMRequestQuery;
const { server } = req;
const savedObjectsClient = server.savedObjects.getScopedSavedObjectsClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ type GenericMetricsRequest = Overwrite<
}
>;

export function transformDataToMetricsChart<
TRequest extends GenericMetricsRequest
>(result: ESSearchResponse<unknown, TRequest>, chartBase: ChartBase) {
export function transformDataToMetricsChart(
result: ESSearchResponse<unknown, GenericMetricsRequest>,
chartBase: ChartBase
) {
const { aggregations, hits } = result;
const timeseriesData = idx(aggregations, _ => _.timeseriesData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const asChildFunctionRenderer = <InjectedProps, OwnProps>(
}

public render() {
return this.props.children(this.getRendererArgs());
return (this.props.children as ChildFunctionRendererProps<InjectedProps>['children'])(
this.getRendererArgs()
);
}

private getRendererArgs = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const getChartColor = (section: InfraMetricLayoutSection, seriesId: strin
const isInfraMetricLayoutVisualizationType = (
subject: any
): subject is InfraMetricLayoutVisualizationType => {
return InfraMetricLayoutVisualizationType[subject] != null;
return subject in InfraMetricLayoutVisualizationType;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ describe('IndexPattern Data Panel', () => {
act(() => {
((inst.setProps as unknown) as (props: unknown) => {})({
...props,
...(propChanges || {}),
...((propChanges as object) || {}),
state: {
...props.state,
...(stateChanges || {}),
...((stateChanges as object) || {}),
},
});
inst.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Subscription } from 'rxjs';
import { idx } from '@kbn/elastic-idx';
import { ml } from '../../services/ml_api_service';
import { getErrorMessage } from '../pages/analytics_management/hooks/use_create_analytics_form';
import { RegressionEvaluateResponse } from '../common';

export type IndexName = string;
export type IndexPattern = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mockCallEndpoint = sinon.stub();
const mockSearchRequest = {};
const mockConfig: ScrollConfig = { duration: '2s', size: 123 };
let realCancellationToken = new CancellationToken();
let isCancelledStub: sinon.SinonStub;
let isCancelledStub: sinon.SinonStub<[], boolean>;

describe('hitIterator', function() {
beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"cheerio": "0.22.0",
"commander": "2.20.0",
"copy-webpack-plugin": "^5.0.4",
"cypress": "^3.4.1",
"cypress": "^3.5.5",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-adapter-utils": "^1.12.0",
Expand Down Expand Up @@ -170,7 +170,7 @@
"tmp": "0.1.0",
"tree-kill": "^1.2.1",
"ts-loader": "^6.0.4",
"typescript": "3.5.3",
"typescript": "3.7.2",
"vinyl-fs": "^3.0.3",
"whatwg-fetch": "^3.0.0",
"xml-crypto": "^1.4.0",
Expand Down Expand Up @@ -208,7 +208,7 @@
"apollo-client": "^2.3.8",
"apollo-link": "^1.2.3",
"apollo-link-error": "^1.1.7",
"apollo-link-http": "^1.5.4",
"apollo-link-http": "^1.5.16",
"apollo-link-schema": "^1.1.0",
"apollo-link-state": "^0.4.1",
"apollo-server-errors": "^2.0.2",
Expand Down
9 changes: 9 additions & 0 deletions x-pack/typings/global_fetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// This type needs to still exist due to apollo-link-http-common hasn't yet updated
// it's usage (https://github.com/apollographql/apollo-link/issues/1131)
declare type GlobalFetch = WindowOrWorkerGlobalScope;
Loading