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

[DX] Bump TS version to v4.1 #83397

Merged
merged 17 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"**/node-jose/node-forge": "^0.10.0",
"**/request": "^2.88.2",
"**/trim": "0.0.3",
"**/typescript": "4.0.2"
"**/typescript": "4.1.1-rc"
},
"engines": {
"node": "12.19.0",
Expand Down Expand Up @@ -827,7 +827,7 @@
"topojson-client": "3.0.0",
"ts-loader": "^7.0.5",
"tsd": "^0.13.1",
"typescript": "4.0.2",
"typescript": "4.1.1-rc",
"typescript-fsa": "^3.0.0",
"typescript-fsa-reducers": "^1.2.1",
"unlazy-loader": "^0.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-archiver/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function runCli() {
output: process.stdout,
});

await new Promise((resolveInput) => {
await new Promise<void>((resolveInput) => {
rl.question(`Press enter when you're done`, () => {
rl.close();
resolveInput();
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ describe('#start()', () => {
// Create an app and a promise that allows us to control when the app completes mounting
const createWaitingApp = (props: Partial<App>): [App, () => void] => {
let finishMount: () => void;
const mountPromise = new Promise((resolve) => (finishMount = resolve));
const mountPromise = new Promise<void>((resolve) => (finishMount = resolve));
const app = {
id: 'some-id',
title: 'some-title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('ApplicationService', () => {
const { register } = service.setup(setupDeps);

let resolveMount: () => void;
const promise = new Promise((resolve) => {
const promise = new Promise<void>((resolve) => {
resolveMount = resolve;
});

Expand Down Expand Up @@ -100,7 +100,7 @@ describe('ApplicationService', () => {
const { register } = service.setup(setupDeps);

let resolveMount: () => void;
const promise = new Promise((resolve) => {
const promise = new Promise<void>((resolve) => {
resolveMount = resolve;
});

Expand Down Expand Up @@ -442,7 +442,7 @@ describe('ApplicationService', () => {
const { register } = service.setup(setupDeps);

let resolveMount: () => void;
const promise = new Promise((resolve) => {
const promise = new Promise<void>((resolve) => {
resolveMount = resolve;
});

Expand Down Expand Up @@ -480,7 +480,7 @@ describe('ApplicationService', () => {
const { register } = service.setup(setupDeps);

let resolveMount: () => void;
const promise = new Promise((resolve) => {
const promise = new Promise<void>((resolve) => {
resolveMount = resolve;
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/ui/app_container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('AppContainer', () => {
});

const flushPromises = async () => {
await new Promise(async (resolve) => {
await new Promise<void>(async (resolve) => {
setImmediate(() => resolve());
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/ui_settings/ui_settings_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class UiSettingsApi {
if (error) {
reject(error);
} else {
resolve(resp);
resolve(resp!);
}
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/client/cluster_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ describe('ClusterClient', () => {
let closeScopedClient: () => void;

internalClient.close.mockReturnValue(
new Promise((resolve) => {
new Promise<void>((resolve) => {
closeInternalClient = resolve;
}).then(() => {
expect(clusterClientClosed).toBe(false);
internalClientClosed = true;
})
);
scopedClient.close.mockReturnValue(
new Promise((resolve) => {
new Promise<void>((resolve) => {
closeScopedClient = resolve;
}).then(() => {
expect(clusterClientClosed).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/appenders/file/file_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class FileAppender implements DisposableAppender {
* Disposes `FileAppender`. Waits for the underlying file stream to be completely flushed and closed.
*/
public async dispose() {
await new Promise((resolve) => {
await new Promise<void>((resolve) => {
if (this.outputStream === undefined) {
return resolve();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class Field extends PureComponent<FieldProps> {

return new Promise((resolve, reject) => {
reader.onload = () => {
resolve(reader.result || undefined);
resolve(reader.result!);
};
reader.onerror = (err) => {
reject(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getPromiseState = (promise: Promise<unknown>): Promise<'resolved' | 'rejec
() => resolve('rejected')
)
),
new Promise<'pending'>((resolve) => resolve()).then(() => 'pending'),
new Promise<'pending'>((resolve) => resolve('pending')).then(() => 'pending'),
]);

const isPending = (promise: Promise<unknown>): Promise<boolean> =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class LegacyCoreEditor implements CoreEditor {
// dirty check for tokenizer state, uses a lot less cycles
// than listening for tokenizerUpdate
waitForLatestTokens(): Promise<void> {
return new Promise((resolve) => {
return new Promise<void>((resolve) => {
const session = this.editor.getSession();
const checkInterval = 25;

Expand Down Expand Up @@ -239,7 +239,7 @@ export class LegacyCoreEditor implements CoreEditor {

private forceRetokenize() {
const session = this.editor.getSession();
return new Promise((resolve) => {
return new Promise<void>((resolve) => {
// force update of tokens, but not on this thread to allow for ace rendering.
setTimeout(function () {
let i;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/console/server/lib/proxy_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const proxyRequest = ({
if (!resolved) {
timeoutReject(Boom.gatewayTimeout('Client request timeout'));
} else {
timeoutResolve();
timeoutResolve(undefined);
}
}, timeout);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import { i18n } from '@kbn/i18n';
import { IEmbeddable } from '../../embeddable_plugin';
import { ActionByType, IncompatibleActionError } from '../../ui_actions_plugin';
import { DASHBOARD_CONTAINER_TYPE, DashboardContainer } from '../embeddable';
import {
DASHBOARD_CONTAINER_TYPE,
DashboardContainer,
DashboardContainerInput,
} from '../embeddable';

export const ACTION_EXPAND_PANEL = 'togglePanel';

Expand All @@ -33,7 +37,9 @@ function isExpanded(embeddable: IEmbeddable) {
throw new IncompatibleActionError();
}

return embeddable.id === embeddable.parent.getInput().expandedPanelId;
return (
embeddable.id === (embeddable.parent.getInput() as DashboardContainerInput).expandedPanelId
);
}

export interface ExpandPanelActionContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function ChangeIndexPattern({
indexPatternRefs: IndexPatternRef[];
onChangeIndexPattern: (newId: string) => void;
indexPatternId?: string;
selectableProps?: EuiSelectableProps;
selectableProps?: EuiSelectableProps<{ value: string }>;
}) {
const [isPopoverOpen, setPopoverIsOpen] = useState(false);

Expand Down Expand Up @@ -86,7 +86,7 @@ export function ChangeIndexPattern({
defaultMessage: 'Change index pattern',
})}
</EuiPopoverTitle>
<EuiSelectable
<EuiSelectable<{ value: string }>
data-test-subj="indexPattern-switcher"
{...selectableProps}
searchable
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/embeddable/public/lib/containers/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export abstract class Container<
return this.children[id] as TEmbeddable;
}

return new Promise((resolve, reject) => {
return new Promise<TEmbeddable>((resolve, reject) => {
const subscription = merge(this.getOutput$(), this.getInput$()).subscribe(() => {
if (this.output.embeddableLoaded[id]) {
subscription.unsubscribe();
Expand All @@ -181,6 +181,7 @@ export abstract class Container<
// If we hit this, the panel was removed before the embeddable finished loading.
if (this.input.panels[id] === undefined) {
subscription.unsubscribe();
// @ts-expect-error undefined in not assignable to TEmbeddable | ErrorEmbeddable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need either to change untilEmbeddableLoaded signature or fix the code @elastic/kibana-app-arch

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe

reject(new Error('The panel was removed before the embeddable finished loading.'));

/cc @stacey-gammon

resolve(undefined);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/embeddable/public/lib/state_transfer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function isEmbeddablePackageState(state: unknown): state is EmbeddablePac

function ensureFieldOfTypeExists(key: string, obj: unknown, type?: string): boolean {
return (
obj &&
Boolean(obj) &&
key in (obj as { [key: string]: unknown }) &&
(!type || typeof (obj as { [key: string]: unknown })[key] === type)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ContactCardEmbeddableFactory
<ContactCardInitializer
onCancel={() => {
modalSession.close();
// @ts-expect-error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined is not assignable to Partial<ContactCardEmbeddableInput> @elastic/kibana-app-arch

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe

reject(new Error('Cancelled!'));

resolve(undefined);
}}
onCreate={(input: { firstName: string; lastName?: string }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function useForm<T extends FormData = FormData, I extends FormData = T>(
return;
}

return new Promise((resolve) => {
return new Promise<void>((resolve) => {
setTimeout(() => {
areSomeFieldValidating = fieldsToArray().some((field) => field.isValidating);
if (areSomeFieldValidating) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const render: ExpressionTypeDefinition<'render', ExpressionValueRender<un
name: 'render',
from: {
'*': <T>(v: T): ExpressionValueRender<T> => ({
type: name,
type: 'render',
as: 'debug',
value: v,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/public/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('ExpressionRenderHandler', () => {
it('sends a next observable once rendering is complete', () => {
const expressionRenderHandler = new ExpressionRenderHandler(element);
expect.assertions(1);
return new Promise((resolve) => {
return new Promise<void>((resolve) => {
expressionRenderHandler.render$.subscribe((renderCount) => {
expect(renderCount).toBe(1);
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ensureMinimumTime', () => {

it('resolves in the amount of time provided, at minimum', async (done) => {
const startTime = new Date().getTime();
const promise = new Promise((resolve) => resolve());
const promise = new Promise<void>((resolve) => resolve());
await ensureMinimumTime(promise, 100);
const endTime = new Date().getTime();
expect(endTime - startTime).toBeGreaterThanOrEqual(100);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/kibana_utils/common/of.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { of } from './of';

describe('of()', () => {
describe('when promise resolves', () => {
const promise = new Promise((resolve) => resolve()).then(() => 123);
const promise = new Promise<void>((resolve) => resolve()).then(() => 123);

test('first member of 3-tuple is the promise value', async () => {
const [result] = await of(promise);
Expand All @@ -40,7 +40,7 @@ describe('of()', () => {
});

describe('when promise rejects', () => {
const promise = new Promise((resolve) => resolve()).then(() => {
const promise = new Promise<void>((resolve) => resolve()).then(() => {
// eslint-disable-next-line no-throw-literal
throw 123;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('useVisualizeAppState', () => {

renderHook(() => useVisualizeAppState(mockServices, eventEmitter, savedVisInstance));

await new Promise((res) => {
await new Promise<void>((res) => {
setTimeout(() => res());
});

Expand Down
2 changes: 1 addition & 1 deletion test/functional/services/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function RemoteProvider({ getService }: FtrProviderContext) {
const coverageJson = await driver
.executeScript('return window.__coverage__')
.catch(() => undefined)
.then((coverage) => coverage && JSON.stringify(coverage));
.then((coverage) => (coverage ? JSON.stringify(coverage) : undefined));
if (coverageJson) {
writeCoverage(coverageJson);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CodeEditor extends Component<

public render() {
const {
name,
id,
label,
isReadOnly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class FieldText extends Component<

public render() {
const {
name,
id,
required,
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MultiFieldText extends Component<

public render() {
const {
name,
id,
required,
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FieldPassword extends Component<

public render() {
const {
name,
id,
required,
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function location(): ExpressionFunctionDefinition<'location', null, {}, P
help,
fn: () => {
return new Promise((resolve) => {
function createLocation(geoposition: Position) {
function createLocation(geoposition: GeolocationPosition) {
const { latitude, longitude } = geoposition.coords;
return resolve({
type: 'datatable',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/shareable_runtime/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const takeMountedSnapshot = (mountedComponent: ReactWrapper<{}, {}, Compo
};

export const waitFor = (fn: () => boolean, stepMs = 100, failAfterMs = 1000) => {
return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
let waitForTimeout: NodeJS.Timeout;

const tryCondition = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export abstract class AbstractExploreDataAction<Context extends { embeddable?: I

constructor(protected readonly params: Params) {}

protected abstract async getUrl(context: Context): Promise<KibanaURL>;
protected abstract getUrl(context: Context): Promise<KibanaURL>;

public async isCompatible({ embeddable }: Context): Promise<boolean> {
if (!embeddable) return false;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/scripts/dev_agent/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ run(

while (!closing) {
await checkin(kibanaUrl, agent, log);
await new Promise((resolve, reject) => setTimeout(() => resolve(), CHECKIN_INTERVAL));
await new Promise<void>((resolve, reject) => setTimeout(() => resolve(), CHECKIN_INTERVAL));
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ describe('test agent checkin new action services', () => {
it('should not fetch actions concurrently', async () => {
const observable = createNewActionsSharedObservable();

const resolves: Array<() => void> = [];
const resolves: Array<(value?: any) => void> = [];
getMockedNewActionSince().mockImplementation(() => {
return new Promise((resolve) => {
return new Promise<any>((resolve) => {
resolves.push(resolve);
});
});
Expand Down
Loading