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

Use ts-expect-error in platform code #69883

Merged
merged 13 commits into from
Jun 30, 2020
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 @@ -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
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
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/retry_call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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
2 changes: 1 addition & 1 deletion src/core/server/http/router/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const {
NoConnections,
RequestTimeout,
Conflict,
// @ts-ignore
// @ts-expect-error
401: NotAuthorized,
// @ts-ignore
// @ts-expect-error
403: Forbidden,
// @ts-ignore
// @ts-expect-error
413: RequestEntityTooLarge,
NotFound,
BadRequest,
Expand Down
11 changes: 5 additions & 6 deletions src/core/utils/deep_freeze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

import { deepFreeze } from './deep_freeze';

it('returns the first argument with all original references', () => {
Expand All @@ -33,39 +32,39 @@ it('returns the first argument with all original references', () => {
it('prevents adding properties to argument', () => {
const frozen = deepFreeze({});
expect(() => {
// @ts-ignore ts knows this shouldn't be possible, but just making sure
// @ts-expect-error ts knows this shouldn't be possible, but just making sure
frozen.foo = true;
}).toThrowError(`object is not extensible`);
});

it('prevents changing properties on argument', () => {
const frozen = deepFreeze({ foo: false });
expect(() => {
// @ts-ignore ts knows this shouldn't be possible, but just making sure
// @ts-expect-error ts knows this shouldn't be possible, but just making sure
frozen.foo = true;
}).toThrowError(`read only property 'foo'`);
});

it('prevents changing properties on nested children of argument', () => {
const frozen = deepFreeze({ foo: { bar: { baz: { box: 1 } } } });
expect(() => {
// @ts-ignore ts knows this shouldn't be possible, but just making sure
// @ts-expect-error ts knows this shouldn't be possible, but just making sure
frozen.foo.bar.baz.box = 2;
}).toThrowError(`read only property 'box'`);
});

it('prevents adding items to a frozen array', () => {
const frozen = deepFreeze({ foo: [1] });
expect(() => {
// @ts-ignore ts knows this shouldn't be possible, but just making sure
// @ts-expect-error ts knows this shouldn't be possible, but just making sure
frozen.foo.push(2);
}).toThrowError(`object is not extensible`);
});

it('prevents reassigning items in a frozen array', () => {
const frozen = deepFreeze({ foo: [1] });
expect(() => {
// @ts-ignore ts knows this shouldn't be possible, but just making sure
// @ts-expect-error ts knows this shouldn't be possible, but just making sure
frozen.foo[0] = 2;
}).toThrowError(`read only property '0'`);
});
16 changes: 3 additions & 13 deletions src/core/utils/deep_freeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

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

/** @public */
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;
import { RecursiveReadonly } from '@kbn/utility-types';

/** @public */
export type Freezable = { [k: string]: any } | any[];
Expand All @@ -50,3 +38,5 @@ export function deepFreeze<T extends Freezable>(object: T) {

return Object.freeze(object) as RecursiveReadonly<T>;
}

export { RecursiveReadonly };
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface KibanaServerRequest extends t.TypeOf<typeof RuntimeKibanaServer
export const RuntimeKibanaUser = t.interface(
{
username: t.string,
roles: t.array(t.string),
roles: t.readonlyArray(t.string),
full_name: t.union([t.null, t.string]),
email: t.union([t.null, t.string]),
enabled: t.boolean,
Expand All @@ -139,7 +139,7 @@ export interface FrameworkAuthenticatedUser<AuthDataType = any> {
kind: 'authenticated';
[internalAuthData]: AuthDataType;
username: string;
roles: string[];
roles: readonly string[];
full_name: string | null;
email: string | null;
enabled: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface FrameworkInfo extends t.TypeOf<typeof RuntimeFrameworkInfo> {}
export const RuntimeFrameworkUser = t.interface(
{
username: t.string,
roles: t.array(t.string),
roles: t.readonlyArray(t.string),
full_name: t.union([t.null, t.string]),
email: t.union([t.null, t.string]),
enabled: t.boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ describe('DashboardOnlyModeRequestInterceptor', () => {

security.authc.getCurrentUser = jest.fn(
(r: KibanaRequest) =>
({
(({
roles: [DASHBOARD_ONLY_MODE_ROLE],
} as AuthenticatedUser)
} as unknown) as AuthenticatedUser)
);

uiSettingsMock = [DASHBOARD_ONLY_MODE_ROLE];
Expand Down
Loading