Skip to content

Commit dd55760

Browse files
committed
Improve the types relating to the Deferred class used in tests.
1 parent be00b4a commit dd55760

4 files changed

Lines changed: 35 additions & 21 deletions

File tree

LoadingCacheValue.test.mjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export default (tests) => {
123123
loading.addEventListener(`${cacheKey}/end`, loadingListener);
124124

125125
const { promise: loadingResult, resolve: loadingResultResolve } =
126-
new Deferred();
126+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
127+
(new Deferred());
127128
const abortController = new AbortController();
128129
const loadingCacheValue = new LoadingCacheValue(
129130
loading,
@@ -204,7 +205,9 @@ export default (tests) => {
204205
const {
205206
promise: firstLoadingResult,
206207
resolve: firstLoadingResultResolve,
207-
} = new Deferred();
208+
} =
209+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
210+
(new Deferred());
208211
const firstAbortController = new AbortController();
209212
const firstLoadingCacheValue = new LoadingCacheValue(
210213
loading,
@@ -242,7 +245,9 @@ export default (tests) => {
242245
const {
243246
promise: secondLoadingResult,
244247
resolve: secondLoadingResultResolve,
245-
} = new Deferred();
248+
} =
249+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
250+
(new Deferred());
246251
const secondAbortController = new AbortController();
247252
const secondLoadingCacheValue = new LoadingCacheValue(
248253
loading,
@@ -369,7 +374,9 @@ export default (tests) => {
369374
const {
370375
promise: firstLoadingResult,
371376
resolve: firstLoadingResultResolve,
372-
} = new Deferred();
377+
} =
378+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
379+
(new Deferred());
373380
const firstAbortController = new AbortController();
374381
const firstLoadingCacheValue = new LoadingCacheValue(
375382
loading,
@@ -407,7 +414,9 @@ export default (tests) => {
407414
const {
408415
promise: secondLoadingResult,
409416
resolve: secondLoadingResultResolve,
410-
} = new Deferred();
417+
} =
418+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
419+
(new Deferred());
411420
const secondAbortController = new AbortController();
412421
const secondLoadingCacheValue = new LoadingCacheValue(
413422
loading,

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Simplified dev dependencies and config for ESLint.
1717
- Fixed issues with GraphQL result related types from `types.mjs`.
1818
- Improved various JSDoc descriptions.
19+
- Improved the types relating to the `Deferred` class used in tests.
1920

2021
## 17.0.0
2122

test/Deferred.mjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
/**
44
* Deferred promise that can be externally resolved or rejected.
5-
* @template T
5+
* @template [Resolves=void] What the promise resolves.
66
*/
77
export default class Deferred {
88
constructor() {
9-
/**
10-
* The promise.
11-
* @type {Promise<T>}
12-
*/
13-
this.promise = new Promise((resolve, reject) => {
14-
/** Resolves the promise. */
15-
this.resolve = resolve;
9+
/** The promise. */
10+
this.promise = /** @type {Promise<Resolves>} */ (
11+
new Promise((resolve, reject) => {
12+
/** Resolves the promise. */
13+
this.resolve = resolve;
1614

17-
/** Rejects the promise. */
18-
this.reject = reject;
19-
});
15+
/** Rejects the promise. */
16+
this.reject = reject;
17+
})
18+
);
2019
}
2120
}

useLoadingEntry.test.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export default (tests) => {
119119
strictEqual(result.error, undefined);
120120

121121
const { promise: loadingA1Result, resolve: loadingA1ResultResolve } =
122-
new Deferred();
122+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
123+
(new Deferred());
123124

124125
/** @type {LoadingCacheValue | undefined} */
125126
let loadingA1CacheValue;
@@ -156,7 +157,8 @@ export default (tests) => {
156157
strictEqual(result.error, undefined);
157158

158159
const { promise: loadingB1Result, resolve: loadingB1ResultResolve } =
159-
new Deferred();
160+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
161+
(new Deferred());
160162

161163
/** @type {LoadingCacheValue | undefined} */
162164
let loadingB1CacheValue;
@@ -197,7 +199,8 @@ export default (tests) => {
197199
const cache = new Cache();
198200
const cacheKeyA = "a";
199201
const { promise: loadingA1Result, resolve: loadingA1ResultResolve } =
200-
new Deferred();
202+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
203+
(new Deferred());
201204
const loadingA1CacheValue = new LoadingCacheValue(
202205
loading,
203206
cache,
@@ -229,7 +232,8 @@ export default (tests) => {
229232
strictEqual(result.error, undefined);
230233

231234
const { promise: loadingA2Result, resolve: loadingA2ResultResolve } =
232-
new Deferred();
235+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
236+
(new Deferred());
233237

234238
/** @type {LoadingCacheValue | undefined} */
235239
let loadingA2CacheValue;
@@ -271,7 +275,8 @@ export default (tests) => {
271275

272276
const cacheKeyB = "b";
273277
const { promise: loadingB1Result, resolve: loadingB1ResultResolve } =
274-
new Deferred();
278+
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
279+
(new Deferred());
275280

276281
/** @type {LoadingCacheValue | undefined} */
277282
let loadingB1CacheValue;

0 commit comments

Comments
 (0)