Skip to content

Commit

Permalink
repo: upgrade to TypeScript 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Oct 29, 2021
1 parent e5e6f92 commit af7ef93
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 62 deletions.
2 changes: 1 addition & 1 deletion dev-packages/localization-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"deepmerge": "^4.2.2",
"fs-extra": "^4.0.2",
"glob": "^7.2.0",
"typescript": "^4.4.3"
"typescript": "~4.4.4"
},
"devDependencies": {
"@theia/ext-scripts": "1.19.0"
Expand Down
9 changes: 8 additions & 1 deletion doc/Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ Please see the latest version (`master`) for the most up-to-date information. Pl

## Guide

### v1.20.0

#### TypeScript 4.4

If you are using TypeScript <= 4.4 and you encounter issues when building your Theia application because your compiler fails to parse our type definitions,
then you should upgrade to TypeScript >= 4.4.

### v1.19.0

#### Runtime System Plugin Resolvement

Introduced in `v1.19.0` was the feature to better support extension-packs which both contribute functionality and reference plugins (by `id`).
The feature works best when there is no runtime plugin resolvement for system (builtin) plugins as it should be done at build time instead.
In order not to change behavior today, the feature is behind an application prop (acting as a flag). If you want to enable better support for
extension-packs and extension-dependencies as builtins the property should be turned off. You can disable the resolvement in your application's
extension-packs and extension-dependencies as builtins the property should be turned off. You can disable the resolvement in your application's
`package.json` like so:


Expand Down
2 changes: 1 addition & 1 deletion license-check-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"npm/npmjs/-/jsdom/11.12.0": "Approved as 'works-with': https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640",
"npm/npmjs/-/jsmin/1.0.1": "Approved as 'works-with': https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640",
"npm/npmjs/-/seek-bzip/1.0.6": "Approved by CQ: https://dev.eclipse.org/ipzilla/show_bug.cgi?id=17349#c7",
"npm/npmjs/-/typescript/4.4.3": "Approved manually: https://github.com/eclipse-theia/theia/pull/10247"
"npm/npmjs/-/typescript/4.4.4": "From ClearlyDefined: Apache-2.0 with a score of 78"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"tslint": "^5.12.0",
"typedoc": "0.20.36",
"typedoc-plugin-external-module-map": "^1.2.1",
"typescript": "^3.9.2",
"typescript": "~4.4.4",
"uuid": "^8.0.0",
"yargs": "^15.3.1"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/authentication-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class AuthenticationServiceImpl implements AuthenticationService {
}
});
this.commands.registerCommand(this.noAccountsCommand, {
execute: () => {},
execute: () => { },
isEnabled: () => false
});
}
Expand Down Expand Up @@ -264,7 +264,7 @@ export class AuthenticationServiceImpl implements AuthenticationService {
// Activate has already been called for the authentication provider, but it cannot block on registering itself
// since this is sync and returns a disposable. So, wait for registration event to fire that indicates the
// provider is now in the map.
await new Promise((resolve, _) => {
await new Promise<void>((resolve, _) => {
this.onDidRegisterAuthenticationProvider(e => {
if (e.id === providerId) {
provider = this.authenticationProviders.get(providerId);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/shell/shell-layout-restorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ShellLayoutRestorer implements CommandContribution {
this.storageService.setData(this.storageKey, undefined);
ThemeService.get().reset(); // Theme service cannot use DI, so the current theme ID is stored elsewhere. Hence the explicit reset.
this.logger.info('<<< The layout has been successfully reset.');
window.location.reload(true);
window.location.reload();
}

storeLayout(app: FrontendApplication): void {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ export class ToolbarAwareTabBar extends ScrollableTabBar {
/**
* Overrides the `contentNode` property getter in PhosphorJS' TabBar.
*/
// @ts-expect-error TS2611 because Phosphor.js implements a getter for `TabBar<T>.contentNode` but it typed it as `readonly contentNode`.
get contentNode(): HTMLUListElement {
return this.tabBarContainer.getElementsByClassName(ToolbarAwareTabBar.Styles.TAB_BAR_CONTENT)[0] as HTMLUListElement;
}
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/browser/source-tree/source-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

/* eslint-disable @typescript-eslint/no-explicit-any */

import { injectable } from 'inversify';
import { MaybePromise } from '../../common/types';
import { TreeImpl, CompositeTreeNode, TreeNode, SelectableTreeNode, ExpandableTreeNode } from '../tree';
Expand Down Expand Up @@ -67,15 +69,15 @@ export class SourceTree extends TreeImpl {
} as TreeElementNode;
}
if (CompositeTreeElementNode.is(updated)) {
delete updated.expanded;
delete updated.children;
delete (updated as any).expanded;
delete (updated as any).children;
}
if (updated) {
if (ExpandableTreeNode.is(updated)) {
delete updated.expanded;
delete (updated as any).expanded;
}
if (CompositeTreeNode.is(updated)) {
delete updated.children;
delete (updated as any).children;
}
return updated;
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ export class ViewContainerLayout extends SplitLayout {
return map(this.items, item => item.widget);
}

// @ts-expect-error TS2611 because Phosphor.js implements a getter for `SplitLayout.widgets` but typed it as `readonly widgets`.
get widgets(): ViewContainerPart[] {
return toArray(this.iter());
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export namespace WaitUntilEvent {
// Asynchronous calls to `waitUntil` should fail.
Object.freeze(waitables);
} finally {
delete asyncEvent['waitUntil'];
delete (asyncEvent as any)['waitUntil'];
}
if (!waitables.length) {
return;
Expand Down Expand Up @@ -390,7 +390,7 @@ export class AsyncEmitter<T extends WaitUntilEvent> extends Emitter<T> {
} catch (e) {
console.error(e);
} finally {
delete asyncEvent['waitUntil'];
delete (asyncEvent as any)['waitUntil'];
}
if (!waitables.length) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/messaging/proxy-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
const method = p.toString();
const capturedError = new Error(`Request '${method}' failed`);
return this.connectionPromise.then(connection =>
new Promise((resolve, reject) => {
new Promise<void>((resolve, reject) => {
try {
if (isNotify) {
connection.sendNotification(method, ...args);
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/node/messaging/ipc-connection-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as cp from 'child_process';
import * as path from 'path';
import { injectable, inject } from 'inversify';
import { Trace, IPCMessageReader, IPCMessageWriter, createMessageConnection, MessageConnection, Message } from 'vscode-ws-jsonrpc';
import { Trace, Tracer, IPCMessageReader, IPCMessageWriter, createMessageConnection, MessageConnection, Message } from 'vscode-ws-jsonrpc';
import { ILogger, ConnectionErrorHandler, DisposableCollection, Disposable } from '../../common';
import { createIpcEnv } from './ipc-protocol';

Expand Down Expand Up @@ -83,10 +83,14 @@ export class IPCConnectionProvider {
info: (message: string) => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${message}`),
log: (message: string) => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${message}`)
});
const traceVerbosity = this.logger.isDebug() ? Trace.Verbose : Trace.Off;
connection.trace(traceVerbosity, {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
log: (message: any, data?: string) => this.logger.debug(`[${options.serverName}: ${childProcess.pid}] ${message}` + (typeof data === 'string' ? ' ' + data : ''))
const tracer: Tracer = {
log: (message: unknown, data?: string) => this.logger.debug(`[${options.serverName}: ${childProcess.pid}] ${message}` + (typeof data === 'string' ? ' ' + data : ''))
};
connection.trace(Trace.Verbose, tracer);
this.logger.isDebug().then(isDebug => {
if (!isDebug) {
connection.trace(Trace.Off, tracer);
}
});
return connection;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/debug/src/browser/debug-session-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export class DebugSessionConnection implements Disposable {
this.onDidCustomEventEmitter.fire(event);
}
} else {
// TODO: Does this branch even make sense?
// @ts-expect-error TS2559
this.fire('exited', event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('directory-archiver', () => {
await archiver.archive(fromPath, path.join(toPath, 'output.tar'));
expect(fs.existsSync(path.join(toPath, 'output.tar'))).to.be.true;
const assertPath = track.mkdirSync('assertPath');
return new Promise(resolve => {
return new Promise<void>(resolve => {
fs.createReadStream(path.join(toPath, 'output.tar')).pipe(extract(assertPath)).on('finish', () => {
expect(fs.readdirSync(assertPath).sort()).to.be.deep.equal(['A.txt', 'B.txt']);
expect(fs.readFileSync(path.join(assertPath, 'A.txt'), { encoding: 'utf8' })).to.be.equal(fs.readFileSync(path.join(fromPath, 'A.txt'), { encoding: 'utf8' }));
Expand Down
2 changes: 1 addition & 1 deletion packages/git/src/node/git-repository-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class GitRepositoryWatcher implements Disposable {
this.skipNextIdle = false;
} else {
const idleTimeout = this.watching ? 5000 : /* super long */ 1000 * 60 * 60 * 24;
await new Promise(resolve => {
await new Promise<void>(resolve => {
const id = setTimeout(resolve, idleTimeout);
this.interruptIdle = () => { clearTimeout(id); resolve(); };
}).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class MonacoEditorProvider {
let keydownListener: monaco.IDisposable | undefined;
const keybindingService = editor.getControl()._standaloneKeybindingService;
for (const listener of keybindingService._store._toDispose) {
if ('_type' in listener && listener['_type'] === 'keydown') {
if ((listener as any)['_type'] === 'keydown') {
keydownListener = listener;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ export interface RenameLocation {
}

export interface RenameProvider {
provideRenameEdits(model: monaco.editor.ITextModel, position: Position, newName: string): PromiseLike<WorkspaceEdit & Rejection>;
resolveRenameLocation?(model: monaco.editor.ITextModel, position: Position): PromiseLike<RenameLocation & Rejection>;
provideRenameEdits(model: monaco.editor.ITextModel, position: theia.Position, newName: string): PromiseLike<WorkspaceEdit & Rejection>;
resolveRenameLocation?(model: monaco.editor.ITextModel, position: theia.Position): PromiseLike<RenameLocation & Rejection>;
}

export interface CallHierarchyDefinition {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/hosted/node/plugin-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class HostedPluginReader implements BackendApplicationContribution {
// the request was already closed
return;
}
if ('code' in e && e['code'] === 'ENOENT') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((e as any)['code'] === 'ENOENT') {
res.status(404).send(`No such file found in '${escape_html(pluginId)}' plugin.`);
} else {
res.status(500).send(`Failed to transfer a file from '${escape_html(pluginId)}' plugin.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ViewColumnService {
) {
let oldColumnValues = new Map<string, number>();
const update = async () => {
await new Promise((resolve => setTimeout(() => resolve())));
await new Promise<void>((resolve => setTimeout(resolve)));
this.updateViewColumns();
this.viewColumnIds.forEach((ids: string[], viewColumn: number) => {
ids.forEach((id: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export class PreferenceTreeGenerator {
};
const isTopLevel = Preference.TreeNode.isTopLevel(newNode);
if (!isTopLevel) {
delete newNode.expanded;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (newNode as any).expanded;
}
newNode.depth = isTopLevel ? 0 : 1;
CompositeTreeNode.addChild(root, newNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class MarkdownPreviewHandler implements PreviewHandler {
return NodeFilter.FILTER_SKIP;
}
};
const treeWalker = document.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, filter, false);
const treeWalker = document.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, filter);
if (treeWalker.nextNode()) {
const element = treeWalker.currentNode as HTMLElement;
return element;
Expand Down Expand Up @@ -198,7 +198,7 @@ export class MarkdownPreviewHandler implements PreviewHandler {
return NodeFilter.FILTER_REJECT;
}
};
const treeWalker = document.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, filter, false);
const treeWalker = document.createTreeWalker(content, NodeFilter.SHOW_ELEMENT, filter);
const lineElements: HTMLElement[] = [];
while (treeWalker.nextNode()) {
const element = treeWalker.currentNode as HTMLElement;
Expand Down
6 changes: 3 additions & 3 deletions packages/process/src/node/multi-ring-buffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ describe('MultiRingBuffer', function (): void {
const buffer = 'abc';

const astream = ringBuffer.getStream();
const p = new Promise(resolve => {
const p = new Promise<void>(resolve => {
astream.on('data', (chunk: string) => {
expect(chunk).to.be.equal(buffer);
resolve();
Expand All @@ -347,7 +347,7 @@ describe('MultiRingBuffer', function (): void {
ringBuffer.enq(buffer);

const astream = ringBuffer.getStream();
const p = new Promise(resolve => {
const p = new Promise<void>(resolve => {
astream.on('data', (chunk: string) => {
expect(chunk).to.be.equal(buffer);
resolve();
Expand Down Expand Up @@ -403,7 +403,7 @@ describe('MultiRingBuffer', function (): void {
ringBuffer.enq(buffer);

const astream = ringBuffer.getStream('hex');
const p = new Promise(resolve => {
const p = new Promise<void>(resolve => {
astream.on('data', (chunk: string) => {
expect(chunk).to.be.equal('74657374');
resolve();
Expand Down
11 changes: 4 additions & 7 deletions packages/process/src/node/raw-process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,13 @@ describe('RawProcess', function (): void {
const args = ['--version'];
const rawProcess = rawProcessFactory({ command: process.execPath, 'args': args });
const p = new Promise<number>((resolve, reject) => {
rawProcess.onError(error => {
reject();
});

rawProcess.onError(reject);
rawProcess.onExit(event => {
if (event.code === undefined) {
reject();
reject(new Error('event.code is undefined'));
} else {
resolve(event.code);
}

resolve(event.code);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class ScmHistoryWidget extends ScmNavigableListWidget<ScmHistoryListNode>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected doLoadMoreRows(params: IndexRange): Promise<any> {
let resolver: () => void;
const promise = new Promise(resolve => resolver = resolve);
const promise = new Promise<void>(resolve => resolver = resolve);
const lastRow = this.scmNodes[params.stopIndex - 1];
if (ScmCommitNode.is(lastRow)) {
const toRevision = lastRow.commitDetails.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,16 @@ describe('ripgrep-search-in-workspace-server', function (): void {
it('fails gracefully when rg isn\'t found', async function (): Promise<void> {
const errorString = await new Promise<string>((resolve, reject) => {
const rgServer = createInstance('/non-existent/rg');

rgServer.setClient({
onResult: (searchId: number, result: SearchInWorkspaceResult): void => {
reject();
},
onDone: (searchId: number, error?: string): void => {
resolve(error);
if (typeof error === 'string') {
resolve(error);
} else {
reject();
}
},
});
rgServer.search('pattern', [rootDirA]);
Expand All @@ -934,7 +937,11 @@ describe('ripgrep-search-in-workspace-server', function (): void {
reject();
},
onDone: (searchId: number, error?: string): void => {
resolve(error);
if (typeof error === 'string') {
resolve(error);
} else {
reject();
}
},
});
rgServer.search('pattern', [rootDirA]);
Expand Down
11 changes: 6 additions & 5 deletions packages/task/src/node/task-server.slow-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Task server / back-end', function (): void {
const messages: string[] = [];

// hook-up to terminal's ws and confirm that it outputs expected tasks' output
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const channel = new TestWebSocketChannel({ server, path: `${terminalsPath}/${terminalId}` });
channel.onError(reject);
channel.onClose((code, reason) => reject(new Error(`channel is closed with '${code}' code and '${reason}' reason`)));
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('Task server / back-end', function (): void {
// create task using raw process
const taskInfo: TaskInfo = await taskServer.run(createProcessTaskConfig('process', executable, [someString]), wsRoot);

await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const toDispose = taskWatcher.onTaskExit((event: TaskExitedEvent) => {
if (event.taskId === taskInfo.taskId && event.code === 0) {
if (typeof taskInfo.terminalId === 'number') {
Expand Down Expand Up @@ -242,8 +242,9 @@ describe('Task server / back-end', function (): void {
taskWatcher.onTaskExit((event: TaskExitedEvent) => {
if (event.taskId !== taskInfo.taskId || event.code === undefined) {
reject(new Error(JSON.stringify(event)));
} else {
resolve(event.code);
}
resolve(event.code);
});
});
// node-pty reports different things on Linux/macOS vs Windows when
Expand Down Expand Up @@ -422,8 +423,8 @@ function createTaskConfigTaskLongRunning(processType: ProcessType): TaskConfigur
};
}

function checkSuccessfulProcessExit(taskInfo: TaskInfo, taskWatcher: TaskWatcher): Promise<object> {
return new Promise<object>((resolve, reject) => {
function checkSuccessfulProcessExit(taskInfo: TaskInfo, taskWatcher: TaskWatcher): Promise<void> {
return new Promise<void>((resolve, reject) => {
const toDispose = taskWatcher.onTaskExit((event: TaskExitedEvent) => {
if (event.taskId === taskInfo.taskId && event.code === 0) {
toDispose.dispose();
Expand Down
Loading

0 comments on commit af7ef93

Please sign in to comment.