Skip to content

Commit 7358419

Browse files
author
denisp22
committed
Replace TypeScript Record types with index signatures.
1 parent 788b5a6 commit 7358419

7 files changed

+26
-22
lines changed

Cache.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
export default class Cache extends EventTarget {
88
/**
9-
* @param {CacheStore} [store] Initial {@link Cache.store cache store} record.
9+
* @param {CacheStore} [store] Initial {@link Cache.store cache store}.
1010
* Defaults to `{}`. Useful for hydrating cache data from a server side
1111
* render prior to the initial client side render.
1212
*/
@@ -65,6 +65,6 @@ export default class Cache extends EventTarget {
6565
*/
6666

6767
/**
68-
* Cache store record.
69-
* @typedef {Record<CacheKey, CacheValue>} CacheStore
68+
* Cache store.
69+
* @typedef {{ [cacheKey: CacheKey]: CacheValue }} CacheStore
7070
*/

Loading.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class Loading extends EventTarget {
1616
* Store of loading {@link CacheKey cache keys} and associated
1717
* {@link LoadingCacheValue loading cache values}. Multiple for the same key
1818
* are set in the order loading started.
19-
* @type {Record<CacheKey, Set<LoadingCacheValue>>}
19+
* @type {{ [cacheKey: CacheKey]: Set<LoadingCacheValue> }}
2020
*/
2121
this.store = {};
2222
}

LoadingCacheValue.test.mjs

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

125125
const { promise: loadingResult, resolve: loadingResultResolve } =
126-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
126+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
127127
(new Deferred());
128128
const abortController = new AbortController();
129129
const loadingCacheValue = new LoadingCacheValue(
@@ -206,7 +206,7 @@ export default (tests) => {
206206
promise: firstLoadingResult,
207207
resolve: firstLoadingResultResolve,
208208
} =
209-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
209+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
210210
(new Deferred());
211211
const firstAbortController = new AbortController();
212212
const firstLoadingCacheValue = new LoadingCacheValue(
@@ -246,7 +246,7 @@ export default (tests) => {
246246
promise: secondLoadingResult,
247247
resolve: secondLoadingResultResolve,
248248
} =
249-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
249+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
250250
(new Deferred());
251251
const secondAbortController = new AbortController();
252252
const secondLoadingCacheValue = new LoadingCacheValue(
@@ -375,7 +375,7 @@ export default (tests) => {
375375
promise: firstLoadingResult,
376376
resolve: firstLoadingResultResolve,
377377
} =
378-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
378+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
379379
(new Deferred());
380380
const firstAbortController = new AbortController();
381381
const firstLoadingCacheValue = new LoadingCacheValue(
@@ -415,7 +415,7 @@ export default (tests) => {
415415
promise: secondLoadingResult,
416416
resolve: secondLoadingResultResolve,
417417
} =
418-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
418+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
419419
(new Deferred());
420420
const secondAbortController = new AbortController();
421421
const secondLoadingCacheValue = new LoadingCacheValue(

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Updated dev dependencies.
1313
- Use the `node:` URL scheme for Node.js builtin module imports in tests.
1414
- Updated ESLint config.
15+
- Replaced TypeScript `Record` types with index signatures.
1516
- Added missing readme “Installation” section import map instructions for [`is-plain-obj`](https://npm.im/is-plain-obj).
1617
- Added [Browserslist](https://browsersl.ist) links to the readme.
1718

fetchOptionsGraphQL.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function fetchOptionsGraphQL(operation) {
3939

4040
form.set("operations", operationJSON);
4141

42-
/** @type {Record<string, Array<string>>} */
42+
/** @type {{ [formFieldName: string]: Array<string> }} */
4343
const map = {};
4444

4545
let i = 0;
@@ -60,7 +60,7 @@ export default function fetchOptionsGraphQL(operation) {
6060

6161
fetchOptions.body = form;
6262
} else {
63-
/** @type {Record<string, string>} */ (fetchOptions.headers)[
63+
/** @type {{ [headerName: string]: string }} */ (fetchOptions.headers)[
6464
"Content-Type"
6565
] = "application/json";
6666
fetchOptions.body = operationJSON;

types.mjs

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export {};
2121
* GraphQL server.
2222
* @typedef {object} GraphQLOperation
2323
* @prop {string} query GraphQL queries or mutations.
24-
* @prop {Record<string, unknown>} [variables] Variables used in the GraphQL
25-
* queries or mutations.
24+
* @prop {{ [variableName: string ]: unknown}} [variables] Variables used in the
25+
* GraphQL queries or mutations.
2626
*/
2727

2828
/**
@@ -35,14 +35,16 @@ export {};
3535
* for hydration.
3636
* @prop {Array<ErrorTypes>} [errors] GraphQL errors from the server, along with
3737
* any loading errors added on the client.
38-
* @prop {Record<string, unknown> | null} [data] GraphQL data.
38+
* @prop {{ [key: string]: unknown } | null} [data] GraphQL data.
3939
*/
4040

4141
/**
4242
* {@link GraphQLResult.errors GraphQL result error}.
4343
* @see [GraphQL spec for response errors](https://spec.graphql.org/October2021/#sec-Errors).
44-
* @template {Record<string, unknown>} [Extensions=Record<string, unknown>]
45-
* Extensions to a standard GraphQL error.
44+
* @template {{
45+
* [key: string]: unknown
46+
* }} [Extensions={ [key: string]: unknown }] Extensions to a standard GraphQL
47+
* error.
4648
* @typedef {object} GraphQLResultError
4749
* @prop {string} message Error message.
4850
* @prop {Array<{ line: number; column: number }>} [locations] GraphQL query
@@ -56,7 +58,8 @@ export {};
5658
* {@link GraphQLResult GraphQL result} loading error generated on the client,
5759
* not the GraphQL server.
5860
* @template {string} Code Error code.
59-
* @template {Record<string, unknown>} [Extensions={}] Error specific details.
61+
* @template {{ [key: string]: unknown }} [Extensions={}] Error specific
62+
* details.
6063
* @typedef {object} GraphQLResultErrorLoading
6164
* @prop {string} message Error message.
6265
* @prop {GraphQLResultErrorLoadingMeta<Code> & Extensions} extensions Error

useLoadingEntry.test.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default (tests) => {
109109
strictEqual(results[0].returned, undefined);
110110

111111
const { promise: loadingA1Result, resolve: loadingA1ResultResolve } =
112-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
112+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
113113
(new Deferred());
114114

115115
/** @type {LoadingCacheValue | undefined} */
@@ -158,7 +158,7 @@ export default (tests) => {
158158
strictEqual(results[3].returned, undefined);
159159

160160
const { promise: loadingB1Result, resolve: loadingB1ResultResolve } =
161-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
161+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
162162
(new Deferred());
163163

164164
/** @type {LoadingCacheValue | undefined} */
@@ -196,7 +196,7 @@ export default (tests) => {
196196
const cache = new Cache();
197197
const cacheKeyA = "a";
198198
const { promise: loadingA1Result, resolve: loadingA1ResultResolve } =
199-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
199+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
200200
(new Deferred());
201201
const loadingA1CacheValue = new LoadingCacheValue(
202202
loading,
@@ -225,7 +225,7 @@ export default (tests) => {
225225
deepStrictEqual(results[0].returned, new Set([loadingA1CacheValue]));
226226

227227
const { promise: loadingA2Result, resolve: loadingA2ResultResolve } =
228-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
228+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
229229
(new Deferred());
230230

231231
/** @type {LoadingCacheValue | undefined} */
@@ -268,7 +268,7 @@ export default (tests) => {
268268

269269
const cacheKeyB = "b";
270270
const { promise: loadingB1Result, resolve: loadingB1ResultResolve } =
271-
/** @type {Deferred<Readonly<Record<string, unknown>>>} */
271+
/** @type {Deferred<Readonly<{ [key: string]: unknown }>>} */
272272
(new Deferred());
273273

274274
/** @type {LoadingCacheValue | undefined} */

0 commit comments

Comments
 (0)