Skip to content

Commit 9f6422b

Browse files
committed
Use the TypeScript v5.5+ JSDoc tag @import to import types in modules.
See: https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag Note that the JSDoc type imports have to be before the real module imports to workaround this TypeScript bug where sometimes the type imports are falsely considered unused: microsoft/TypeScript#58368 (comment) microsoft/TypeScript#58969
1 parent f237800 commit 9f6422b

40 files changed

+248
-170
lines changed

CacheContext.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @ts-check
22

3-
import React from "react";
3+
/** @import Cache from "./Cache.mjs" */
44

5-
/** @typedef {import("./Cache.mjs").default} Cache */
5+
import React from "react";
66

77
/**
88
* [React context](https://reactjs.org/docs/context.html) for a

HYDRATION_TIME_MS.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
/** @typedef {import("./useAutoLoad.mjs").default} useAutoLoad */
3+
/** @import useAutoLoad from "./useAutoLoad.mjs" */
44

55
/**
66
* Number of milliseconds after the first client render that’s considered the

Loading.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// @ts-check
22

3-
/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */
4-
/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */
5-
/** @typedef {import("./LoadingCacheValue.mjs").default} LoadingCacheValue */
3+
/**
4+
* @import { CacheKey, CacheValue } from "./Cache.mjs"
5+
* @import LoadingCacheValue from "./LoadingCacheValue.mjs"
6+
*/
67

78
/**
89
* Loading store.

LoadingCacheValue.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// @ts-check
22

3+
/**
4+
* @import { CacheEventMap, CacheKey, CacheValue } from "./Cache.mjs"
5+
* @import { LoadingEventMap } from "./Loading.mjs"
6+
*/
7+
38
import Cache from "./Cache.mjs";
49
import cacheEntrySet from "./cacheEntrySet.mjs";
510
import Loading from "./Loading.mjs";
611

7-
/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */
8-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
9-
/** @typedef {import("./Loading.mjs").LoadingEventMap} LoadingEventMap */
10-
1112
/**
1213
* Controls loading a {@link CacheValue cache value}. It dispatches this
1314
* sequence of events:
@@ -20,7 +21,7 @@ export default class LoadingCacheValue {
2021
/**
2122
* @param {Loading} loading Loading to update.
2223
* @param {Cache} cache Cache to update.
23-
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
24+
* @param {CacheKey} cacheKey Cache key.
2425
* @param {Promise<CacheValue>} loadingResult Resolves the loading result
2526
* (including any loading errors) to be set as the
2627
* {@link CacheValue cache value} if loading isn’t aborted. Shouldn’t

LoadingContext.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @ts-check
22

3-
import React from "react";
3+
/** @import Loading from "./Loading.mjs" */
44

5-
/** @typedef {import("./Loading.mjs").default} Loading */
5+
import React from "react";
66

77
/**
88
* [React context](https://reactjs.org/docs/context.html) for a

cacheDelete.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// @ts-check
22

3+
/**
4+
* @import { CacheEventMap, CacheKey } from "./Cache.mjs"
5+
* @import { CacheKeyMatcher } from "./types.mjs"
6+
*/
7+
38
import Cache from "./Cache.mjs";
49
import cacheEntryDelete from "./cacheEntryDelete.mjs";
510

6-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
7-
/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */
8-
911
/**
1012
* Deletes {@link Cache.store cache store} entries, dispatching the
1113
* {@linkcode Cache} event {@link CacheEventMap.delete `delete`}. Useful after a
1214
* user logs out.
1315
* @param {Cache} cache Cache to update.
14-
* @param {import("./types.mjs").CacheKeyMatcher} [cacheKeyMatcher] Matches
16+
* @param {CacheKeyMatcher} [cacheKeyMatcher] Matches
1517
* {@link CacheKey cache keys} to delete. By default all are matched.
1618
*/
1719
export default function cacheDelete(cache, cacheKeyMatcher) {

cacheEntryDelete.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// @ts-check
22

3-
import Cache from "./Cache.mjs";
3+
/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */
44

5-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
5+
import Cache from "./Cache.mjs";
66

77
/**
88
* Deletes a {@link Cache.store cache store} entry, dispatching the
99
* {@linkcode Cache} event {@link CacheEventMap.delete `delete`}.
1010
* @param {Cache} cache Cache to update.
11-
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
11+
* @param {CacheKey} cacheKey Cache key.
1212
*/
1313
export default function cacheEntryDelete(cache, cacheKey) {
1414
if (!(cache instanceof Cache))

cacheEntryPrune.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// @ts-check
22

3+
/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */
4+
35
import Cache from "./Cache.mjs";
46
import cacheEntryDelete from "./cacheEntryDelete.mjs";
57

6-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
7-
88
/**
99
* Prunes a {@link Cache.store cache store} entry (if present) by dispatching
1010
* the {@linkcode Cache} event {@link CacheEventMap.prune `prune`} and if no
1111
* listener cancels it via `event.preventDefault()`, using
1212
* {@linkcode cacheEntryDelete}.
1313
* @param {Cache} cache Cache to update.
14-
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
14+
* @param {CacheKey} cacheKey Cache key.
1515
*/
1616
export default function cacheEntryPrune(cache, cacheKey) {
1717
if (!(cache instanceof Cache))

cacheEntrySet.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// @ts-check
22

3-
import Cache from "./Cache.mjs";
3+
/** @import { CacheEventMap, CacheKey, CacheValue } from "./Cache.mjs" */
44

5-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
5+
import Cache from "./Cache.mjs";
66

77
/**
88
* Sets a {@link Cache.store cache store} entry, dispatching the
99
* {@linkcode Cache} event {@link CacheEventMap.set `set`}.
1010
* @param {Cache} cache Cache to update.
11-
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
12-
* @param {import("./Cache.mjs").CacheValue} cacheValue Cache value.
11+
* @param {CacheKey} cacheKey Cache key.
12+
* @param {CacheValue} cacheValue Cache value.
1313
*/
1414
export default function cacheEntrySet(cache, cacheKey, cacheValue) {
1515
if (!(cache instanceof Cache))

cacheEntryStale.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// @ts-check
22

3-
import Cache from "./Cache.mjs";
3+
/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */
44

5-
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
5+
import Cache from "./Cache.mjs";
66

77
/**
88
* Stales a {@link Cache.store cache store} entry (throwing an error if missing)
99
* by dispatching the {@linkcode Cache} event
1010
* {@link CacheEventMap.stale `stale`} to signal it should probably be reloaded.
1111
* @param {Cache} cache Cache to update.
12-
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
12+
* @param {CacheKey} cacheKey Cache key.
1313
*/
1414
export default function cacheEntryStale(cache, cacheKey) {
1515
if (!(cache instanceof Cache))

0 commit comments

Comments
 (0)