Skip to content

Commit

Permalink
Use ts-expect-error in platform code (#69883) (#70287)
Browse files Browse the repository at this point in the history
* ts-ignore --> ts-expect-error

* fix error with mutable array

* fix errors in consumers code

* update SOM

* fix FeatureConfig & Feature compatibility

* do not re-export from code. it breaks built version

* update docs

* add eslint rule for platform team code

* remove test. this is covered by ts-expect-error in unit tests

Co-authored-by: Elastic Machine <[email protected]>
# Conflicts:
#	src/core/utils/integration_tests/__fixtures__/frozen_object_mutation/tsconfig.json
  • Loading branch information
mshustov authored Jun 30, 2020
1 parent 57550cf commit 03e7216
Show file tree
Hide file tree
Showing 64 changed files with 134 additions and 286 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,5 +1043,22 @@ module.exports = {
...require('eslint-config-prettier/@typescript-eslint').rules,
},
},

{
files: [
// platform-team owned code
'src/core/**',
'x-pack/plugins/features/**',
'x-pack/plugins/licensing/**',
'x-pack/plugins/global_search/**',
'x-pack/plugins/cloud/**',
'packages/kbn-config-schema',
'src/plugins/status_page/**',
'src/plugins/saved_objects_management/**',
],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 'error',
},
},
],
};
1 change: 0 additions & 1 deletion docs/development/core/public/kibana-plugin-core-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [PublicAppInfo](./kibana-plugin-core-public.publicappinfo.md) | Public information about a registered [application](./kibana-plugin-core-public.app.md) |
| [PublicLegacyAppInfo](./kibana-plugin-core-public.publiclegacyappinfo.md) | Information about a registered [legacy application](./kibana-plugin-core-public.legacyapp.md) |
| [PublicUiSettingsParams](./kibana-plugin-core-public.publicuisettingsparams.md) | A sub-set of [UiSettingsParams](./kibana-plugin-core-public.uisettingsparams.md) exposed to the client-side. |
| [RecursiveReadonly](./kibana-plugin-core-public.recursivereadonly.md) | |
| [SavedObjectAttribute](./kibana-plugin-core-public.savedobjectattribute.md) | Type definition for a Saved Object attribute value |
| [SavedObjectAttributeSingle](./kibana-plugin-core-public.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-core-public.savedobjectattribute.md) |
| [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) | SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) |
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [PluginName](./kibana-plugin-core-server.pluginname.md) | Dedicated type for plugin name/id that is supposed to make Map/Set/Arrays that use it as a key or value more obvious. |
| [PluginOpaqueId](./kibana-plugin-core-server.pluginopaqueid.md) | |
| [PublicUiSettingsParams](./kibana-plugin-core-server.publicuisettingsparams.md) | A sub-set of [UiSettingsParams](./kibana-plugin-core-server.uisettingsparams.md) exposed to the client-side. |
| [RecursiveReadonly](./kibana-plugin-core-server.recursivereadonly.md) | |
| [RedirectResponseOptions](./kibana-plugin-core-server.redirectresponseoptions.md) | HTTP response parameters for redirection response |
| [RequestHandler](./kibana-plugin-core-server.requesthandler.md) | A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) functions. |
| [RequestHandlerContextContainer](./kibana-plugin-core-server.requesthandlercontextcontainer.md) | An object that handles registration of http request context providers. |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
QueryStringInput: React.FC<Pick<Props, "query" | "placeholder" | "onChange" | "onSubmit" | "prepend" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition">>
QueryStringInput: React.FC<Pick<Props, "query" | "prepend" | "placeholder" | "onChange" | "onSubmit" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition">>
```
3 changes: 2 additions & 1 deletion packages/kbn-utility-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export type Ensure<T, X> = T extends X ? T : never;

// If we define this inside RecursiveReadonly TypeScript complains.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface RecursiveReadonlyArray<T> extends Array<RecursiveReadonly<T>> {}
export interface RecursiveReadonlyArray<T> extends ReadonlyArray<RecursiveReadonly<T>> {}

export type RecursiveReadonly<T> = T extends (...args: any) => any
? T
: T extends any[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('#start', () => {
appIds: ['app1', 'app2', 'legacyApp1', 'legacyApp2'],
});

// @ts-ignore TypeScript knows this shouldn't be possible
// @ts-expect-error TypeScript knows this shouldn't be possible
expect(() => (capabilities.foo = 'foo')).toThrowError();
});

Expand All @@ -59,7 +59,7 @@ describe('#start', () => {
appIds: ['app1', 'app2', 'legacyApp1', 'legacyApp2'],
});

// @ts-ignore TypeScript knows this shouldn't be possible
// @ts-expect-error TypeScript knows this shouldn't be possible
expect(() => (capabilities.foo = 'foo')).toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { RecursiveReadonly } from '@kbn/utility-types';

import { Capabilities } from '../../../types/capabilities';
import { deepFreeze, RecursiveReadonly } from '../../../utils';
import { deepFreeze } from '../../../utils';
import { HttpStart } from '../../http';

interface StartDeps {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { Observable } from 'rxjs';
import { History } from 'history';
import { RecursiveReadonly } from '@kbn/utility-types';

import { Capabilities } from './capabilities';
import { ChromeStart } from '../chrome';
Expand All @@ -30,7 +31,6 @@ import { NotificationsStart } from '../notifications';
import { OverlayStart } from '../overlays';
import { PluginOpaqueId } from '../plugins';
import { IUiSettingsClient } from '../ui_settings';
import { RecursiveReadonly } from '../../utils';
import { SavedObjectsStart } from '../saved_objects';
import { AppCategory } from '../../types';
import { ScopedHistory } from './scoped_history';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('PersistedLog', () => {

describe('internal functionality', () => {
test('reads from storage', () => {
// @ts-ignore
// @ts-expect-error
const log = new PersistedLog(historyName, { maxLength: 10 }, storage);

expect(storage.getItem).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ describe('RecentlyAccessed#start()', () => {
let originalLocalStorage: Storage;
beforeAll(() => {
originalLocalStorage = window.localStorage;
// @ts-ignore
// @ts-expect-error
window.localStorage = new LocalStorageMock();
});
beforeEach(() => localStorage.clear());
// @ts-ignore
// @ts-expect-error
afterAll(() => (window.localStorage = originalLocalStorage));

const getStart = async () => {
Expand Down
1 change: 0 additions & 1 deletion src/core/public/chrome/ui/header/header_help_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ class HeaderHelpMenuUI extends Component<Props, State> {
);

return (
// @ts-ignore repositionOnScroll doesn't exist in EuiPopover
<EuiPopover
anchorPosition="downRight"
button={button}
Expand Down
1 change: 0 additions & 1 deletion src/core/public/chrome/ui/header/recent_links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { EuiNavDrawerGroup } from '@elastic/eui';
import { RecentNavLink } from './nav_link';

Expand Down
4 changes: 2 additions & 2 deletions src/core/public/http/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

// @ts-ignore
// @ts-expect-error
import fetchMock from 'fetch-mock/es5/client';
import { readFileSync } from 'fs';
import { join } from 'path';
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('Fetch', () => {
fetchMock.get('*', {});
await expect(
fetchInstance.fetch(
// @ts-ignore
// @ts-expect-error
{ path: '/', headers: { hello: 'world' } },
{ headers: { hello: 'mars' } }
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/http/http_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

// @ts-ignore
// @ts-expect-error
import fetchMock from 'fetch-mock/es5/client';
import { loadingServiceMock } from './http_service.test.mocks';

Expand Down
1 change: 0 additions & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import {
/** @interal */
export { CoreContext, CoreSystem } from './core_system';
export {
RecursiveReadonly,
DEFAULT_APP_CATEGORIES,
getFlattenedObject,
URLMeaningfulParts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('setup.getCspConfig()', () => {

const csp = injectedMetadata.setup().getCspConfig();
expect(() => {
// @ts-ignore TS knows this shouldn't be possible
csp.warnLegacyBrowsers = false;
}).toThrowError();
});
Expand Down Expand Up @@ -100,11 +99,11 @@ describe('setup.getPlugins()', () => {
plugins.push({ id: 'new-plugin', plugin: {} as DiscoveredPlugin });
}).toThrowError();
expect(() => {
// @ts-ignore TS knows this shouldn't be possible
// @ts-expect-error TS knows this shouldn't be possible
plugins[0].name = 'changed';
}).toThrowError();
expect(() => {
// @ts-ignore TS knows this shouldn't be possible
// @ts-expect-error TS knows this shouldn't be possible
plugins[0].newProp = 'changed';
}).toThrowError();
});
Expand Down Expand Up @@ -136,7 +135,7 @@ describe('setup.getLegacyMetadata()', () => {
foo: true,
});
expect(() => {
// @ts-ignore TS knows this shouldn't be possible
// @ts-expect-error TS knows this shouldn't be possible
legacyMetadata.foo = false;
}).toThrowError();
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/integrations/styles/styles_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Subscription } from 'rxjs';

import { IUiSettingsClient } from '../../ui_settings';
import { CoreService } from '../../../types';
// @ts-ignore
// @ts-expect-error
import disableAnimationsCss from '!!raw-loader!./disable_animations.css';

interface StartDeps {
Expand Down
1 change: 0 additions & 1 deletion src/core/public/kbn_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function __kbnBootstrap__() {
const APM_ENABLED = process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && apmConfig != null;

if (APM_ENABLED) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { init, apm } = require('@elastic/apm-rum');
if (apmConfig.globalLabels) {
Expand Down
8 changes: 1 addition & 7 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import { PublicUiSettingsParams as PublicUiSettingsParams_2 } from 'src/core/ser
import { PutScriptParams } from 'elasticsearch';
import { PutTemplateParams } from 'elasticsearch';
import React from 'react';
import { RecursiveReadonly } from '@kbn/utility-types';
import { ReindexParams } from 'elasticsearch';
import { ReindexRethrottleParams } from 'elasticsearch';
import { RenderSearchTemplateParams } from 'elasticsearch';
Expand Down Expand Up @@ -1158,13 +1159,6 @@ export type PublicLegacyAppInfo = Omit<LegacyApp, 'updater$'> & {
// @public
export type PublicUiSettingsParams = Omit<UiSettingsParams, 'schema'>;

// Warning: (ae-forgotten-export) The symbol "RecursiveReadonlyArray" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type RecursiveReadonly<T> = T extends (...args: any[]) => any ? T : T extends any[] ? RecursiveReadonlyArray<T[number]> : T extends object ? Readonly<{
[K in keyof T]: RecursiveReadonly<T[K]>;
}> : T;

// Warning: (ae-missing-release-tag) "SavedObject" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/saved_objects/saved_objects_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('SavedObjectsClient', () => {
sortOrder: 'sort', // Not currently supported by API
};

// @ts-ignore
// @ts-expect-error
savedObjectsClient.find(options);
expect(http.fetch.mock.calls).toMatchInlineSnapshot(`
Array [
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/ui_settings/ui_settings_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

// @ts-ignore
// @ts-expect-error
import fetchMock from 'fetch-mock/es5/client';
import * as Rx from 'rxjs';
import { takeUntil, toArray } from 'rxjs/operators';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/legacy/retry_call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function migrationsRetryCallCluster(
error instanceof esErrors.RequestTimeout ||
error instanceof esErrors.AuthenticationException ||
error instanceof esErrors.AuthorizationException ||
// @ts-ignore
// @ts-expect-error
error instanceof esErrors.Gone ||
error?.body?.error?.type === 'snapshot_in_progress_exception'
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/http/cookie_session_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { Request, Server } from 'hapi';
import hapiAuthCookie from 'hapi-auth-cookie';
// @ts-ignore no TS definitions
// @ts-expect-error no TS definitions
import Statehood from 'statehood';

import { KibanaRequest, ensureRawRequest } from './router';
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/http/router/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { Url } from 'url';
import { Request, ApplicationState } from 'hapi';
import { Observable, fromEvent, merge } from 'rxjs';
import { shareReplay, first, takeUntil } from 'rxjs/operators';
import { RecursiveReadonly } from '@kbn/utility-types';

import { deepFreeze, RecursiveReadonly } from '../../../utils';
import { deepFreeze } from '../../../utils';
import { Headers } from './headers';
import { RouteMethod, RouteConfigOptions, validBodyOutput, isSafeMethod } from './route';
import { KibanaSocket, IKibanaSocket } from './socket';
Expand Down Expand Up @@ -156,7 +157,7 @@ export class KibanaRequest<
public readonly params: Params,
public readonly query: Query,
public readonly body: Body,
// @ts-ignore we will use this flag as soon as http request proxy is supported in the core
// @ts-expect-error we will use this flag as soon as http request proxy is supported in the core
// until that time we have to expose all the headers
private readonly withoutSecretHeaders: boolean
) {
Expand Down
1 change: 0 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ export {
} from './metrics';

export {
RecursiveReadonly,
DEFAULT_APP_CATEGORIES,
getFlattenedObject,
URLMeaningfulParts,
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/legacy/config/get_unused_config_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { difference, get, set } from 'lodash';
// @ts-ignore
// @ts-expect-error
import { getTransform } from '../../../../legacy/deprecation/index';
import { unset } from '../../../../legacy/utils';
import { getFlattenedObject } from '../../../utils';
Expand Down
1 change: 0 additions & 1 deletion src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {

import { BehaviorSubject, throwError } from 'rxjs';

// @ts-ignore: implicit any for JS file
import { ClusterManager as MockClusterManager } from '../../../cli/cluster/cluster_manager';
import KbnServer from '../../../legacy/server/kbn_server';
import { Config, Env, ObjectToConfigAdapter } from '../config';
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/legacy/logging/legacy_logging_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import { ServerExtType } from 'hapi';
import Podium from 'podium';
// @ts-ignore: implicit any for JS file
// @ts-expect-error: implicit any for JS file
import { Config } from '../../../../legacy/server/config';
// @ts-ignore: implicit any for JS file
// @ts-expect-error: implicit any for JS file
import { setupLogging } from '../../../../legacy/server/logging';
import { LogLevel } from '../../logging/log_level';
import { LogRecord } from '../../logging/log_record';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/legacy/plugins/find_legacy_plugin_specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { toArray, tap, distinct, map } from 'rxjs/operators';
import {
findPluginSpecs,
defaultConfig,
// @ts-ignore
// @ts-expect-error
} from '../../../../legacy/plugin_discovery/find_plugin_specs.js';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { collectUiExports as collectLegacyUiExports } from '../../../../legacy/ui/ui_exports/collect_ui_exports';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import { Observable } from 'rxjs';
import { Type } from '@kbn/config-schema';
import { RecursiveReadonly } from '@kbn/utility-types';

import { RecursiveReadonly } from 'kibana/public';
import { ConfigPath, EnvironmentMode, PackageInfo, ConfigDeprecationProvider } from '../config';
import { LoggerFactory } from '../logging';
import { KibanaConfigType } from '../kibana_config';
Expand Down
Loading

0 comments on commit 03e7216

Please sign in to comment.