diff --git a/CacheContext.mjs b/CacheContext.mjs index 990a751..604de73 100644 --- a/CacheContext.mjs +++ b/CacheContext.mjs @@ -1,8 +1,8 @@ // @ts-check -import React from "react"; +/** @import Cache from "./Cache.mjs" */ -/** @typedef {import("./Cache.mjs").default} Cache */ +import React from "react"; /** * [React context](https://reactjs.org/docs/context.html) for a diff --git a/HYDRATION_TIME_MS.mjs b/HYDRATION_TIME_MS.mjs index dbf55f6..5d73e53 100644 --- a/HYDRATION_TIME_MS.mjs +++ b/HYDRATION_TIME_MS.mjs @@ -1,6 +1,6 @@ // @ts-check -/** @typedef {import("./useAutoLoad.mjs").default} useAutoLoad */ +/** @import useAutoLoad from "./useAutoLoad.mjs" */ /** * Number of milliseconds after the first client render that’s considered the diff --git a/Loading.mjs b/Loading.mjs index 75a52a7..5357a34 100644 --- a/Loading.mjs +++ b/Loading.mjs @@ -1,8 +1,9 @@ // @ts-check -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */ -/** @typedef {import("./LoadingCacheValue.mjs").default} LoadingCacheValue */ +/** + * @import { CacheKey, CacheValue } from "./Cache.mjs" + * @import LoadingCacheValue from "./LoadingCacheValue.mjs" + */ /** * Loading store. diff --git a/LoadingCacheValue.mjs b/LoadingCacheValue.mjs index 28817a9..e604446 100644 --- a/LoadingCacheValue.mjs +++ b/LoadingCacheValue.mjs @@ -1,13 +1,14 @@ // @ts-check +/** + * @import { CacheEventMap, CacheKey, CacheValue } from "./Cache.mjs" + * @import { LoadingEventMap } from "./Loading.mjs" + */ + import Cache from "./Cache.mjs"; import cacheEntrySet from "./cacheEntrySet.mjs"; import Loading from "./Loading.mjs"; -/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ -/** @typedef {import("./Loading.mjs").LoadingEventMap} LoadingEventMap */ - /** * Controls loading a {@link CacheValue cache value}. It dispatches this * sequence of events: @@ -20,7 +21,7 @@ export default class LoadingCacheValue { /** * @param {Loading} loading Loading to update. * @param {Cache} cache Cache to update. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. * @param {Promise} loadingResult Resolves the loading result * (including any loading errors) to be set as the * {@link CacheValue cache value} if loading isn’t aborted. Shouldn’t diff --git a/LoadingContext.mjs b/LoadingContext.mjs index ae5c939..d86eeef 100644 --- a/LoadingContext.mjs +++ b/LoadingContext.mjs @@ -1,8 +1,8 @@ // @ts-check -import React from "react"; +/** @import Loading from "./Loading.mjs" */ -/** @typedef {import("./Loading.mjs").default} Loading */ +import React from "react"; /** * [React context](https://reactjs.org/docs/context.html) for a diff --git a/cacheDelete.mjs b/cacheDelete.mjs index 5230033..2bacb2a 100644 --- a/cacheDelete.mjs +++ b/cacheDelete.mjs @@ -1,17 +1,19 @@ // @ts-check +/** + * @import { CacheEventMap, CacheKey } from "./Cache.mjs" + * @import { CacheKeyMatcher } from "./types.mjs" + */ + import Cache from "./Cache.mjs"; import cacheEntryDelete from "./cacheEntryDelete.mjs"; -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ - /** * Deletes {@link Cache.store cache store} entries, dispatching the * {@linkcode Cache} event {@link CacheEventMap.delete `delete`}. Useful after a * user logs out. * @param {Cache} cache Cache to update. - * @param {import("./types.mjs").CacheKeyMatcher} [cacheKeyMatcher] Matches + * @param {CacheKeyMatcher} [cacheKeyMatcher] Matches * {@link CacheKey cache keys} to delete. By default all are matched. */ export default function cacheDelete(cache, cacheKeyMatcher) { diff --git a/cacheEntryDelete.mjs b/cacheEntryDelete.mjs index 286fb1f..1559fdb 100644 --- a/cacheEntryDelete.mjs +++ b/cacheEntryDelete.mjs @@ -1,14 +1,14 @@ // @ts-check -import Cache from "./Cache.mjs"; +/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ +import Cache from "./Cache.mjs"; /** * Deletes a {@link Cache.store cache store} entry, dispatching the * {@linkcode Cache} event {@link CacheEventMap.delete `delete`}. * @param {Cache} cache Cache to update. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. */ export default function cacheEntryDelete(cache, cacheKey) { if (!(cache instanceof Cache)) diff --git a/cacheEntryPrune.mjs b/cacheEntryPrune.mjs index 3f221a2..7fdbc0f 100644 --- a/cacheEntryPrune.mjs +++ b/cacheEntryPrune.mjs @@ -1,17 +1,17 @@ // @ts-check +/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */ + import Cache from "./Cache.mjs"; import cacheEntryDelete from "./cacheEntryDelete.mjs"; -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ - /** * Prunes a {@link Cache.store cache store} entry (if present) by dispatching * the {@linkcode Cache} event {@link CacheEventMap.prune `prune`} and if no * listener cancels it via `event.preventDefault()`, using * {@linkcode cacheEntryDelete}. * @param {Cache} cache Cache to update. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. */ export default function cacheEntryPrune(cache, cacheKey) { if (!(cache instanceof Cache)) diff --git a/cacheEntrySet.mjs b/cacheEntrySet.mjs index 6556f90..8084d9f 100644 --- a/cacheEntrySet.mjs +++ b/cacheEntrySet.mjs @@ -1,15 +1,15 @@ // @ts-check -import Cache from "./Cache.mjs"; +/** @import { CacheEventMap, CacheKey, CacheValue } from "./Cache.mjs" */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ +import Cache from "./Cache.mjs"; /** * Sets a {@link Cache.store cache store} entry, dispatching the * {@linkcode Cache} event {@link CacheEventMap.set `set`}. * @param {Cache} cache Cache to update. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. - * @param {import("./Cache.mjs").CacheValue} cacheValue Cache value. + * @param {CacheKey} cacheKey Cache key. + * @param {CacheValue} cacheValue Cache value. */ export default function cacheEntrySet(cache, cacheKey, cacheValue) { if (!(cache instanceof Cache)) diff --git a/cacheEntryStale.mjs b/cacheEntryStale.mjs index faf144e..729de12 100644 --- a/cacheEntryStale.mjs +++ b/cacheEntryStale.mjs @@ -1,15 +1,15 @@ // @ts-check -import Cache from "./Cache.mjs"; +/** @import { CacheEventMap, CacheKey } from "./Cache.mjs" */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ +import Cache from "./Cache.mjs"; /** * Stales a {@link Cache.store cache store} entry (throwing an error if missing) * by dispatching the {@linkcode Cache} event * {@link CacheEventMap.stale `stale`} to signal it should probably be reloaded. * @param {Cache} cache Cache to update. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. */ export default function cacheEntryStale(cache, cacheKey) { if (!(cache instanceof Cache)) diff --git a/cachePrune.mjs b/cachePrune.mjs index be611df..c2000d2 100644 --- a/cachePrune.mjs +++ b/cachePrune.mjs @@ -1,15 +1,18 @@ // @ts-check +/** + * @import { CacheKey } from "./Cache.mjs" + * @import { CacheKeyMatcher } from "./types.mjs" + */ + import Cache from "./Cache.mjs"; import cacheEntryPrune from "./cacheEntryPrune.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ - /** * Prunes {@link Cache.store cache store} entries by using * {@linkcode cacheEntryPrune} for each entry. Useful after a mutation. * @param {Cache} cache Cache to update. - * @param {import("./types.mjs").CacheKeyMatcher} [cacheKeyMatcher] Matches + * @param {CacheKeyMatcher} [cacheKeyMatcher] Matches * {@link CacheKey cache keys} to prune. By default all are matched. */ export default function cachePrune(cache, cacheKeyMatcher) { diff --git a/cacheStale.mjs b/cacheStale.mjs index 9f12961..be7b500 100644 --- a/cacheStale.mjs +++ b/cacheStale.mjs @@ -1,15 +1,18 @@ // @ts-check +/** + * @import { CacheKey } from "./Cache.mjs" + * @import { CacheKeyMatcher } from "./types.mjs" + */ + import Cache from "./Cache.mjs"; import cacheEntryStale from "./cacheEntryStale.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ - /** * Stales {@link Cache.store cache store} entries by using * {@linkcode cacheEntryStale} for each entry. Useful after a mutation. * @param {Cache} cache Cache to update. - * @param {import("./types.mjs").CacheKeyMatcher} [cacheKeyMatcher] Matches + * @param {CacheKeyMatcher} [cacheKeyMatcher] Matches * {@link CacheKey cache keys} to stale. By default all are matched. */ export default function cacheStale(cache, cacheKeyMatcher) { diff --git a/changelog.md b/changelog.md index 00f4052..e2ddd2e 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ - Updated Node.js support to `^18.18.0 || ^20.9.0 || >=22.0.0`. - Use the Node.js test runner API and remove the dev dependency [`test-director`](https://npm.im/test-director). - Refactored tests to use the standard `AbortController`, `AbortSignal`, `Event`, `EventTarget`, `File`, `FormData`, and `Response` APIs available in modern Node.js and removed the dev dependencies [`abort-controller`](https://npm.im/abort-controller), [`event-target-shim`](https://npm.im/event-target-shim), and [`node-fetch`](https://npm.im/node-fetch). +- Use the TypeScript v5.5+ JSDoc tag `@import` to import types in modules. ### Patch diff --git a/fetchGraphQL.mjs b/fetchGraphQL.mjs index e440d89..7bd5920 100644 --- a/fetchGraphQL.mjs +++ b/fetchGraphQL.mjs @@ -1,13 +1,22 @@ // @ts-check +/** + * @import { CacheValue } from "./Cache.mjs" + * @import { + * GraphQLResult, + * GraphQLResultError, + * GraphQLResultErrorLoadingFetch, + * GraphQLResultErrorResponseHttpStatus, + * GraphQLResultErrorResponseJsonParse, + * GraphQLResultErrorResponseMalformed, + * } from "./types.mjs" + */ + const ERROR_CODE_FETCH_ERROR = "FETCH_ERROR"; const ERROR_CODE_RESPONSE_HTTP_STATUS = "RESPONSE_HTTP_STATUS"; const ERROR_CODE_RESPONSE_JSON_PARSE_ERROR = "RESPONSE_JSON_PARSE_ERROR"; const ERROR_CODE_RESPONSE_MALFORMED = "RESPONSE_MALFORMED"; -/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */ -/** @typedef {import("./types.mjs").GraphQLResult} GraphQLResult */ - /** * Fetches a GraphQL operation, always resolving a * {@link GraphQLResult GraphQL result} suitable for use as a @@ -45,7 +54,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { if (!response.ok) resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseHttpStatus} */ ({ + /** @type {GraphQLResultErrorResponseHttpStatus} */ ({ message: `HTTP ${response.status} status.`, extensions: { client: true, @@ -65,7 +74,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { if (typeof json !== "object" || !json || Array.isArray(json)) resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseMalformed}*/ ({ + /** @type {GraphQLResultErrorResponseMalformed}*/ ({ message: "Response JSON isn’t an object.", extensions: { client: true, @@ -79,7 +88,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { if (!hasErrors && !hasData) resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseMalformed}*/ ({ + /** @type {GraphQLResultErrorResponseMalformed}*/ ({ message: "Response JSON is missing an `errors` or `data` property.", extensions: { @@ -94,7 +103,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { if (hasErrors) if (!Array.isArray(json.errors)) resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseMalformed}*/ ({ + /** @type {GraphQLResultErrorResponseMalformed}*/ ({ message: "Response JSON `errors` property isn’t an array.", extensions: { @@ -114,7 +123,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { Array.isArray(json.data) ) resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseMalformed}*/ ({ + /** @type {GraphQLResultErrorResponseMalformed}*/ ({ message: "Response JSON `data` property isn’t an object or null.", extensions: { @@ -131,7 +140,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { // Response JSON parse error. ({ message }) => { resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorResponseJsonParse} */ ({ + /** @type {GraphQLResultErrorResponseJsonParse} */ ({ message: "Response JSON parse error.", extensions: { client: true, @@ -147,7 +156,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { // Fetch error. ({ message }) => { resultErrors.push( - /** @type {import("./types.mjs").GraphQLResultErrorLoadingFetch} */ ({ + /** @type {GraphQLResultErrorLoadingFetch} */ ({ message: "Fetch error.", extensions: { client: true, @@ -166,24 +175,21 @@ export default function fetchGraphQL(fetchUri, fetchOptions) { /** * {@linkcode fetchGraphQL} {@link GraphQLResult GraphQL result}. - * @typedef {import("./types.mjs").GraphQLResult< - * FetchGraphQLResultError - * >} FetchGraphQLResult + * @typedef {GraphQLResult} FetchGraphQLResult */ /** * {@linkcode fetchGraphQL} {@link GraphQLResult.errors GraphQL result error}. * @typedef {FetchGraphQLResultErrorLoading - * | import("./types.mjs").GraphQLResultError - * } FetchGraphQLResultError + * | GraphQLResultError} FetchGraphQLResultError */ /** * {@linkcode fetchGraphQL} {@link GraphQLResult.errors GraphQL result error} * that’s generated on the client, not the GraphQL server. - * @typedef {import("./types.mjs").GraphQLResultErrorLoadingFetch - * | import("./types.mjs").GraphQLResultErrorResponseHttpStatus - * | import("./types.mjs").GraphQLResultErrorResponseJsonParse - * | import("./types.mjs").GraphQLResultErrorResponseMalformed + * @typedef {GraphQLResultErrorLoadingFetch + * | GraphQLResultErrorResponseHttpStatus + * | GraphQLResultErrorResponseJsonParse + * | GraphQLResultErrorResponseMalformed * } FetchGraphQLResultErrorLoading */ diff --git a/fetchOptionsGraphQL.mjs b/fetchOptionsGraphQL.mjs index 5e1c5c9..1880ddd 100644 --- a/fetchOptionsGraphQL.mjs +++ b/fetchOptionsGraphQL.mjs @@ -1,10 +1,10 @@ // @ts-check +/** @import { GraphQLOperation } from "./types.mjs" */ + import extractFiles from "extract-files/extractFiles.mjs"; import isExtractableFile from "extract-files/isExtractableFile.mjs"; -/** @typedef {import("./types.mjs").GraphQLOperation} GraphQLOperation */ - /** * Creates default {@link RequestInit `fetch` options} for a * {@link GraphQLOperation GraphQL operation}. If the operation contains files diff --git a/test/createReactTestRenderer.mjs b/test/createReactTestRenderer.mjs index 96f65d2..306dd63 100644 --- a/test/createReactTestRenderer.mjs +++ b/test/createReactTestRenderer.mjs @@ -1,13 +1,18 @@ // @ts-check +/** + * @import { ReactNode } from "react" + * @import { ReactTestRenderer as TestRenderer } from "react-test-renderer" + */ + import ReactTestRenderer from "react-test-renderer"; /** * Creates a React test renderer. - * @param {import("react").ReactNode} reactRoot Root React node to render. + * @param {ReactNode} reactRoot Root React node to render. */ export default function createReactTestRenderer(reactRoot) { - /** @type {import("react-test-renderer").ReactTestRenderer | undefined} */ + /** @type {TestRenderer | undefined} */ let testRenderer; ReactTestRenderer.act(() => { @@ -17,7 +22,5 @@ export default function createReactTestRenderer(reactRoot) { ); }); - return /** @type {import("react-test-renderer").ReactTestRenderer} */ ( - testRenderer - ); + return /** @type {TestRenderer} */ (testRenderer); } diff --git a/types.mjs b/types.mjs index 6bc6600..4ff590e 100644 --- a/types.mjs +++ b/types.mjs @@ -1,8 +1,9 @@ // @ts-check -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./fetchGraphQL.mjs").default} fetchGraphQL */ -/** @typedef {import("./LoadingCacheValue.mjs").default} LoadingCacheValue */ +/** + * @import { CacheKey } from "./Cache.mjs" + * @import LoadingCacheValue from "./LoadingCacheValue.mjs" + */ // Prevent a TypeScript error when importing this module in a JSDoc type. export {}; diff --git a/useAutoAbortLoad.mjs b/useAutoAbortLoad.mjs index 005711b..459e498 100644 --- a/useAutoAbortLoad.mjs +++ b/useAutoAbortLoad.mjs @@ -1,7 +1,9 @@ // @ts-check -/** @typedef {import("./LoadingCacheValue.mjs").default} LoadingCacheValue */ -/** @typedef {import("./types.mjs").Loader} Loader */ +/** + * @import LoadingCacheValue from "./LoadingCacheValue.mjs" + * @import { Loader } from "./types.mjs" + */ import React from "react"; diff --git a/useAutoAbortLoad.test.mjs b/useAutoAbortLoad.test.mjs index 8dea9ac..68cd507 100644 --- a/useAutoAbortLoad.test.mjs +++ b/useAutoAbortLoad.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { notStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -41,14 +46,14 @@ describe("React hook `useAutoAbortLoad`.", { concurrency: true }, () => { /** * @type {Array<{ - * loader: import("./types.mjs").Loader, + * loader: Loader, * hadArgs: boolean, * loadingCacheValue: LoadingCacheValue * }>} */ const loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { const loadingCacheValue = new LoadingCacheValue( loading, @@ -67,7 +72,7 @@ describe("React hook `useAutoAbortLoad`.", { concurrency: true }, () => { return loadingCacheValue; } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { const loadingCacheValue = new LoadingCacheValue( loading, @@ -86,7 +91,7 @@ describe("React hook `useAutoAbortLoad`.", { concurrency: true }, () => { return loadingCacheValue; } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useAutoLoad.mjs b/useAutoLoad.mjs index 88fde0c..e5f81cc 100644 --- a/useAutoLoad.mjs +++ b/useAutoLoad.mjs @@ -1,20 +1,23 @@ // @ts-check +/** + * @import { CacheKey } from "./Cache.mjs" + * @import { Loader } from "./types.mjs" + * @import useWaterfallLoad from "./useWaterfallLoad.mjs" + */ + import useAutoAbortLoad from "./useAutoAbortLoad.mjs"; import useCacheEntryPrunePrevention from "./useCacheEntryPrunePrevention.mjs"; import useLoadOnDelete from "./useLoadOnDelete.mjs"; import useLoadOnMount from "./useLoadOnMount.mjs"; import useLoadOnStale from "./useLoadOnStale.mjs"; -/** @typedef {import("./useWaterfallLoad.mjs").default} useWaterfallLoad */ -/** @typedef {import("./types.mjs").Loader} Loader */ - /** * React hook to prevent a {@link Cache.store cache store} entry from being * pruned while the component is mounted and automatically keep it loaded. * Previous loading that started via this hook aborts when new loading starts * via this hook, the hook arguments change, or the component unmounts. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. * @param {Loader} load Memoized function that starts the loading. * @returns {Loader} Memoized {@link Loader loader} created from the `load` * argument, that automatically aborts the last loading when the memoized diff --git a/useAutoLoad.test.mjs b/useAutoLoad.test.mjs index f3170b4..7f7a808 100644 --- a/useAutoLoad.test.mjs +++ b/useAutoLoad.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { ok, strictEqual, throws } from "node:assert"; @@ -68,7 +73,7 @@ describe("React hook `useAutoLoad`.", { concurrency: true }, () => { */ const loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function load() { const loadingCacheValue = new LoadingCacheValue( loading, @@ -88,7 +93,7 @@ describe("React hook `useAutoLoad`.", { concurrency: true }, () => { // Test load on mount. - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useCache.test.mjs b/useCache.test.mjs index d9b0df4..5501c96 100644 --- a/useCache.test.mjs +++ b/useCache.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import { deepStrictEqual, ok, strictEqual } from "node:assert"; import { describe, it } from "node:test"; @@ -19,7 +21,7 @@ describe("React hook `useCache`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -35,7 +37,7 @@ describe("React hook `useCache`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -63,7 +65,7 @@ describe("React hook `useCache`.", { concurrency: true }, () => { it("Getting the cache.", () => { const cacheA = new Cache(); - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useCacheEntry.mjs b/useCacheEntry.mjs index 924dfdd..2916fbf 100644 --- a/useCacheEntry.mjs +++ b/useCacheEntry.mjs @@ -1,13 +1,12 @@ // @ts-check +/** @import { CacheKey, CacheValue } from "./Cache.mjs" */ + import React from "react"; import useCache from "./useCache.mjs"; import useForceUpdate from "./useForceUpdate.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./Cache.mjs").CacheValue} CacheValue */ - /** * React hook to get a {@link CacheValue cache value} using its * {@link CacheKey cache key}. diff --git a/useCacheEntry.test.mjs b/useCacheEntry.test.mjs index d29f056..50e419f 100644 --- a/useCacheEntry.test.mjs +++ b/useCacheEntry.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -35,7 +37,7 @@ describe("React hook `useCacheEntry`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -51,7 +53,7 @@ describe("React hook `useCacheEntry`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -80,7 +82,7 @@ describe("React hook `useCacheEntry`.", { concurrency: true }, () => { const cache = new Cache(); const cacheKeyA = "a"; - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -164,7 +166,7 @@ describe("React hook `useCacheEntry`.", { concurrency: true }, () => { [cacheKeyB]: cacheValueB1, }); - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -243,7 +245,7 @@ describe("React hook `useCacheEntry`.", { concurrency: true }, () => { [cacheKey]: cacheValue, }); - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( diff --git a/useCacheEntryPrunePrevention.mjs b/useCacheEntryPrunePrevention.mjs index 3550c1a..cae63c9 100644 --- a/useCacheEntryPrunePrevention.mjs +++ b/useCacheEntryPrunePrevention.mjs @@ -1,17 +1,16 @@ // @ts-check +/** @import Cache, { CacheEventMap, CacheKey } from "./Cache.mjs" */ + import React from "react"; import useCache from "./useCache.mjs"; -/** @typedef {import("./Cache.mjs").default} Cache */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ - /** * React hook to prevent a {@link Cache.store cache store} entry from being * pruned, by canceling the cache entry deletion for * {@link CacheEventMap.prune `prune`} events with `event.preventDefault()`. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. + * @param {CacheKey} cacheKey Cache key. */ export default function useCacheEntryPrunePrevention(cacheKey) { if (typeof cacheKey !== "string") diff --git a/useCacheEntryPrunePrevention.test.mjs b/useCacheEntryPrunePrevention.test.mjs index c2977d3..1376abb 100644 --- a/useCacheEntryPrunePrevention.test.mjs +++ b/useCacheEntryPrunePrevention.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -37,7 +39,7 @@ describe( }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -56,7 +58,7 @@ describe( }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -90,7 +92,7 @@ describe( }; const cache = new Cache({ ...initialCacheStore }); - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useForceUpdate.test.mjs b/useForceUpdate.test.mjs index e5e38a3..c3ebf9e 100644 --- a/useForceUpdate.test.mjs +++ b/useForceUpdate.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import { ok, strictEqual } from "node:assert"; import { describe, it } from "node:test"; @@ -13,7 +15,7 @@ import useForceUpdate from "./useForceUpdate.mjs"; describe("React hook `useForceUpdate`.", { concurrency: true }, () => { it("Forcing an update.", async () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( diff --git a/useLoadGraphQL.mjs b/useLoadGraphQL.mjs index d725d8c..177164a 100644 --- a/useLoadGraphQL.mjs +++ b/useLoadGraphQL.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { CacheKey } from "./Cache.mjs" */ + import React from "react"; import fetchGraphQL from "./fetchGraphQL.mjs"; @@ -79,8 +81,7 @@ export default function useLoadGraphQL() { /** * Loads a GraphQL operation, using {@linkcode fetchGraphQL}. * @callback LoadGraphQL - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key to store the - * loading result under. + * @param {CacheKey} cacheKey Cache key to store the loading result under. * @param {string} fetchUri [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) * URI. * @param {RequestInit} fetchOptions [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) diff --git a/useLoadGraphQL.test.mjs b/useLoadGraphQL.test.mjs index b3eae75..2d6623d 100644 --- a/useLoadGraphQL.test.mjs +++ b/useLoadGraphQL.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, fail, ok, strictEqual, throws } from "node:assert"; @@ -31,7 +33,7 @@ describe("React hook `useLoadGraphQL`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -47,7 +49,7 @@ describe("React hook `useLoadGraphQL`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -75,7 +77,7 @@ describe("React hook `useLoadGraphQL`.", { concurrency: true }, () => { it("Loading context missing.", () => { const cache = new Cache(); - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -100,7 +102,7 @@ describe("React hook `useLoadGraphQL`.", { concurrency: true }, () => { it("Loading context value not a `Loading` instance.", () => { const cache = new Cache(); - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -141,7 +143,7 @@ describe("React hook `useLoadGraphQL`.", { concurrency: true }, () => { /** * @type {Array< - * import("./test/ReactHookTest.mjs").ReactHookResult< + * ReactHookResult< * ReturnType * > * >} diff --git a/useLoadOnDelete.mjs b/useLoadOnDelete.mjs index b8ee09d..79bfa32 100644 --- a/useLoadOnDelete.mjs +++ b/useLoadOnDelete.mjs @@ -1,19 +1,20 @@ // @ts-check +/** + * @import { CacheEventMap, CacheKey } from "./Cache.mjs" + * @import { Loader } from "./types.mjs" + */ + import React from "react"; import useCache from "./useCache.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ - /** * React hook to load a {@link Cache.store cache store} entry after it’s * {@link CacheEventMap.delete deleted}, if there isn’t loading for the * {@link CacheKey cache key} that started after. * @param {CacheKey} cacheKey Cache key. - * @param {import("./types.mjs").Loader} load Memoized function that starts the - * loading. + * @param {Loader} load Memoized function that starts the loading. */ export default function useLoadOnDelete(cacheKey, load) { if (typeof cacheKey !== "string") diff --git a/useLoadOnDelete.test.mjs b/useLoadOnDelete.test.mjs index 183b774..9ce0033 100644 --- a/useLoadOnDelete.test.mjs +++ b/useLoadOnDelete.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -22,7 +27,7 @@ import useLoadOnDelete from "./useLoadOnDelete.mjs"; describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { /** * Dummy loader for testing. - * @type {import("./types.mjs").Loader} + * @type {Loader} */ const dummyLoader = () => new LoadingCacheValue( @@ -61,7 +66,7 @@ describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -77,7 +82,7 @@ describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -118,7 +123,7 @@ describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -128,7 +133,7 @@ describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -138,7 +143,7 @@ describe("React hook `useLoadOnDelete`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useLoadOnMount.mjs b/useLoadOnMount.mjs index f9d998f..39d9c03 100644 --- a/useLoadOnMount.mjs +++ b/useLoadOnMount.mjs @@ -1,13 +1,16 @@ // @ts-check +/** + * @import Cache, { CacheKey } from "./Cache.mjs" + * @import { Loader } from "./types.mjs" + */ + import React from "react"; import HYDRATION_TIME_MS from "./HYDRATION_TIME_MS.mjs"; import HydrationTimeStampContext from "./HydrationTimeStampContext.mjs"; import useCache from "./useCache.mjs"; -/** @typedef {import("./Cache.mjs").default} Cache */ - /** * React hook to automatically load a {@link Cache.store cache store} entry * after the component mounts or the {@link CacheContext cache context} or any @@ -15,9 +18,8 @@ import useCache from "./useCache.mjs"; * {@link HYDRATION_TIME_MS hydration time} if the * {@link HydrationTimeStampContext hydration time stamp context} is populated * and the {@link Cache.store cache store} entry is already populated. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. - * @param {import("./types.mjs").Loader} load Memoized function that starts the - * loading. + * @param {CacheKey} cacheKey Cache key. + * @param {Loader} load Memoized function that starts the loading. */ export default function useLoadOnMount(cacheKey, load) { if (typeof cacheKey !== "string") @@ -40,8 +42,8 @@ export default function useLoadOnMount(cacheKey, load) { /** * @type {{ * cache: Cache, - * cacheKey: import("./Cache.mjs").CacheKey, - * load: import("./types.mjs").Loader + * cacheKey: CacheKey, + * load: Loader, * } | undefined} */ (undefined), ); diff --git a/useLoadOnMount.test.mjs b/useLoadOnMount.test.mjs index b1a7195..2d818c2 100644 --- a/useLoadOnMount.test.mjs +++ b/useLoadOnMount.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -22,7 +27,7 @@ import useLoadOnMount from "./useLoadOnMount.mjs"; describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { /** * Dummy loader for testing. - * @type {import("./types.mjs").Loader} + * @type {Loader} */ const dummyLoader = () => new LoadingCacheValue( @@ -61,7 +66,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -77,7 +82,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -105,7 +110,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { it("Hydration time stamp context value not undefined or a number.", () => { const cache = new Cache(); - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -150,7 +155,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -160,7 +165,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -170,7 +175,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -329,7 +334,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -339,7 +344,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -349,7 +354,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -504,7 +509,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -514,7 +519,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -524,7 +529,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -700,7 +705,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -710,7 +715,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -720,7 +725,7 @@ describe("React hook `useLoadOnMount`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useLoadOnStale.mjs b/useLoadOnStale.mjs index b33efb3..c26c46d 100644 --- a/useLoadOnStale.mjs +++ b/useLoadOnStale.mjs @@ -1,19 +1,20 @@ // @ts-check +/** + * @import { CacheEventMap, CacheKey } from "./Cache.mjs" + * @import { Loader } from "./types.mjs" + */ + import React from "react"; import useCache from "./useCache.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */ - /** * React hook to load a {@link Cache.store cache store} entry after becomes * {@link CacheEventMap.stale stale}, if there isn’t loading for the * {@link CacheKey cache key} that started after. * @param {CacheKey} cacheKey Cache key. - * @param {import("./types.mjs").Loader} load Memoized function that starts the - * loading. + * @param {Loader} load Memoized function that starts the loading. */ export default function useLoadOnStale(cacheKey, load) { if (typeof cacheKey !== "string") diff --git a/useLoadOnStale.test.mjs b/useLoadOnStale.test.mjs index c4ffc49..408cfb1 100644 --- a/useLoadOnStale.test.mjs +++ b/useLoadOnStale.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -21,7 +26,7 @@ import useLoadOnStale from "./useLoadOnStale.mjs"; describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { /** * Dummy loader for testing. - * @type {import("./types.mjs").Loader} + * @type {Loader} */ const dummyLoader = () => new LoadingCacheValue( @@ -60,7 +65,7 @@ describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -76,7 +81,7 @@ describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -117,7 +122,7 @@ describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { /** @type {Array<{ loader: Function, hadArgs: boolean }>} */ let loadCalls = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadA() { loadCalls.push({ loader: loadA, @@ -127,7 +132,7 @@ describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function loadB() { loadCalls.push({ loader: loadB, @@ -137,7 +142,7 @@ describe("React hook `useLoadOnStale`.", { concurrency: true }, () => { return dummyLoader(); } - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useLoading.test.mjs b/useLoading.test.mjs index 10fca99..760f823 100644 --- a/useLoading.test.mjs +++ b/useLoading.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import { deepStrictEqual, ok, strictEqual } from "node:assert"; import { describe, it } from "node:test"; @@ -19,7 +21,7 @@ describe("React hook `useLoading`.", { concurrency: true }, () => { }); it("Loading context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -38,7 +40,7 @@ describe("React hook `useLoading`.", { concurrency: true }, () => { }); it("Loading context value not a `Loading` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -66,7 +68,7 @@ describe("React hook `useLoading`.", { concurrency: true }, () => { it("Getting the loading.", () => { const loadingA = new Loading(); - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useLoadingEntry.mjs b/useLoadingEntry.mjs index 88963b4..3c29945 100644 --- a/useLoadingEntry.mjs +++ b/useLoadingEntry.mjs @@ -1,13 +1,15 @@ // @ts-check +/** + * @import { CacheKey } from "./Cache.mjs" + * @import LoadingCacheValue from "./LoadingCacheValue.mjs" + */ + import React from "react"; import useForceUpdate from "./useForceUpdate.mjs"; import useLoading from "./useLoading.mjs"; -/** @typedef {import("./Cache.mjs").CacheKey} CacheKey */ -/** @typedef {import("./LoadingCacheValue.mjs").default} LoadingCacheValue */ - /** * React hook to get the {@link LoadingCacheValue loading cache values} for a * given {@link CacheKey cache key}. diff --git a/useLoadingEntry.test.mjs b/useLoadingEntry.test.mjs index cf32c10..c5bc16f 100644 --- a/useLoadingEntry.test.mjs +++ b/useLoadingEntry.test.mjs @@ -1,5 +1,7 @@ // @ts-check +/** @import { ReactHookResult } from "./test/ReactHookTest.mjs" */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, strictEqual, throws } from "node:assert"; @@ -36,7 +38,7 @@ describe("React hook `useLoadingEntry`.", { concurrency: true }, () => { }); it("Loading context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -55,7 +57,7 @@ describe("React hook `useLoadingEntry`.", { concurrency: true }, () => { }); it("Loading context value not a `Loading` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -85,7 +87,7 @@ describe("React hook `useLoadingEntry`.", { concurrency: true }, () => { const cache = new Cache(); const cacheKeyA = "a"; - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( @@ -198,7 +200,7 @@ describe("React hook `useLoadingEntry`.", { concurrency: true }, () => { new AbortController(), ); - /** @type {Array} */ + /** @type {Array} */ const results = []; const testRenderer = createReactTestRenderer( diff --git a/useWaterfallLoad.mjs b/useWaterfallLoad.mjs index 0b63baf..bbe5c2f 100644 --- a/useWaterfallLoad.mjs +++ b/useWaterfallLoad.mjs @@ -1,22 +1,25 @@ // @ts-check +/** + * @import waterfallRender from "react-waterfall-render/waterfallRender.mjs" + * @import { CacheKey } from "./Cache.mjs" + * @import { Loader } from "./types.mjs" + * @import useAutoLoad from "./useAutoLoad.mjs" + */ + import React from "react"; import WaterfallRenderContext from "react-waterfall-render/WaterfallRenderContext.mjs"; import LoadingCacheValue from "./LoadingCacheValue.mjs"; import useCache from "./useCache.mjs"; -/** @typedef {import("./useAutoLoad.mjs").default} useAutoLoad */ -/** @typedef {import("react-waterfall-render/waterfallRender.mjs").default} waterfallRender */ - /** * React hook to load a {@link Cache.store cache store} entry if the * {@link WaterfallRenderContext waterfall render context} is populated, i.e. * when {@link waterfallRender waterfall rendering} for either a server side * render or to preload components in a browser environment. - * @param {import("./Cache.mjs").CacheKey} cacheKey Cache key. - * @param {import("./types.mjs").Loader} load Memoized function that starts the - * loading. + * @param {CacheKey} cacheKey Cache key. + * @param {Loader} load Memoized function that starts the loading. * @returns {boolean} Did loading start. If so, it’s efficient for the component * to return `null` since this render will be discarded anyway for a re-render * onces the loading ends. diff --git a/useWaterfallLoad.test.mjs b/useWaterfallLoad.test.mjs index 6838b1d..d78bcdb 100644 --- a/useWaterfallLoad.test.mjs +++ b/useWaterfallLoad.test.mjs @@ -1,5 +1,10 @@ // @ts-check +/** + * @import { ReactHookResult } from "./test/ReactHookTest.mjs" + * @import { Loader } from "./types.mjs" + */ + import "./test/polyfillCustomEvent.mjs"; import { deepStrictEqual, ok, rejects, strictEqual, throws } from "node:assert"; @@ -22,7 +27,7 @@ import useWaterfallLoad from "./useWaterfallLoad.mjs"; describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { /** * Dummy loader for testing. - * @type {import("./types.mjs").Loader} + * @type {Loader} */ const dummyLoader = () => new LoadingCacheValue( @@ -61,7 +66,7 @@ describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { }); it("Cache context missing.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -77,7 +82,7 @@ describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { }); it("Cache context value not a `Cache` instance.", () => { - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -107,7 +112,7 @@ describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { let didLoad = false; - /** @type {Array} */ + /** @type {Array} */ const results = []; createReactTestRenderer( @@ -173,7 +178,7 @@ describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { /** @type {Array} */ const hookReturns = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function load() { loadCalls.push(!!arguments.length); @@ -231,7 +236,7 @@ describe("React hook `useWaterfallLoad`.", { concurrency: true }, () => { /** @type {Array} */ const hookReturns = []; - /** @type {import("./types.mjs").Loader} */ + /** @type {Loader} */ function load() { loadCalls.push(!!arguments.length);