Skip to content

Commit 134dcf2

Browse files
core: improve Deferred typings (#10455)
For some reason `Deferred` objects allow you to resolve them with `undefined` even though the corresponding promise only mentions `T`. Remove the optional `value` when resolving. Default to `void` if `T` is unspecified.
1 parent a89ec61 commit 134dcf2

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
2-
- [plugindev] Renamed HostedPlugin(Server|Client) to PluginDev(Server|Client)
2+
3+
## v1.20.0 - 11/25/2021
4+
5+
[1.20.0 Milestone](https://github.com/eclipse-theia/theia/milestone/28)
6+
7+
<a name="breaking_changes_1.20.0">[Breaking Changes:](#breaking_changes_1.20.0)</a>
8+
9+
- [plugindev] Renamed HostedPlugin(Server|Client) to PluginDev(Server|Client) [#10352](https://github.com/eclipse-theia/theia/pull/10352)
10+
- [core] `value` is now not optional in `Deferred<T>.resolve(value: T)` [#10455](https://github.com/eclipse-theia/theia/pull/10455)
11+
- [core] `T` defaults to `void` if not specified when defining a `Deferred` [#10455](https://github.com/eclipse-theia/theia/pull/10455)
12+
313
## v1.19.0 - 10/28/2021
414

515
[1.19.0 Milestone](https://github.com/eclipse-theia/theia/milestone/25)

packages/core/src/common/promise-util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import { CancellationToken, cancelled } from './cancellation';
2020
* Simple implementation of the deferred pattern.
2121
* An object that exposes a promise and functions to resolve and reject it.
2222
*/
23-
export class Deferred<T> {
23+
export class Deferred<T = void> {
2424
state: 'resolved' | 'rejected' | 'unresolved' = 'unresolved';
25-
resolve: (value?: T) => void;
25+
resolve: (value: T) => void;
2626
reject: (err?: any) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
2727

2828
promise = new Promise<T>((resolve, reject) => {
2929
this.resolve = result => {
30-
resolve(result as T);
30+
resolve(result);
3131
if (this.state === 'unresolved') {
3232
this.state = 'resolved';
3333
}

packages/vsx-registry/src/browser/vsx-extension-editor.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ export class VSXExtensionEditor extends ReactWidget {
7777
};
7878

7979
protected resolveScrollContainer = (element: VSXExtensionEditorComponent | null) => {
80-
this.deferredScrollContainer.resolve(element?.scrollContainer);
80+
if (!element) {
81+
this.deferredScrollContainer.reject(new Error('element is null'));
82+
} else if (!element.scrollContainer) {
83+
this.deferredScrollContainer.reject(new Error('element.scrollContainer is undefined'));
84+
} else {
85+
this.deferredScrollContainer.resolve(element.scrollContainer);
86+
}
8187
};
8288

8389
protected render(): React.ReactNode {

packages/workspace/src/node/default-workspace-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class WorkspaceCliContribution implements CliContribution {
4343
if (!wsPath) {
4444
wsPath = args['root-dir'] as string;
4545
if (!wsPath) {
46-
this.workspaceRoot.resolve();
46+
this.workspaceRoot.resolve(undefined);
4747
return;
4848
}
4949
}

0 commit comments

Comments
 (0)