diff --git a/packages/dom-ready/README.md b/packages/dom-ready/README.md index 6b9ea8ea5ab20e..f3f19529152870 100644 --- a/packages/dom-ready/README.md +++ b/packages/dom-ready/README.md @@ -32,11 +32,7 @@ domReady( function () { _Parameters_ -- _callback_ `Callback`: A function to execute after the DOM is ready. - -_Returns_ - -- `void`: +- _callback_ `VoidFunction`: A function to execute after the DOM is ready. diff --git a/packages/dom-ready/src/index.js b/packages/dom-ready/src/index.ts similarity index 55% rename from packages/dom-ready/src/index.js rename to packages/dom-ready/src/index.ts index 6f187a6b3e8444..29d6d81a6b0319 100644 --- a/packages/dom-ready/src/index.js +++ b/packages/dom-ready/src/index.ts @@ -1,21 +1,7 @@ -/** - * @typedef {() => void} Callback - * - * TODO: Remove this typedef and inline `() => void` type. - * - * This typedef is used so that a descriptive type is provided in our - * automatically generated documentation. - * - * An in-line type `() => void` would be preferable, but the generated - * documentation is `null` in that case. - * - * @see https://github.com/WordPress/gutenberg/issues/18045 - */ - /** * Specify a function to execute when the DOM is fully loaded. * - * @param {Callback} callback A function to execute after the DOM is ready. + * @param callback A function to execute after the DOM is ready. * * @example * ```js @@ -25,10 +11,8 @@ * //do something after DOM loads. * } ); * ``` - * - * @return {void} */ -export default function domReady( callback ) { +export default function domReady( callback: VoidFunction ) { if ( typeof document === 'undefined' ) { return; } diff --git a/packages/dom-ready/src/test/index.test.js b/packages/dom-ready/src/test/index.test.ts similarity index 88% rename from packages/dom-ready/src/test/index.test.js rename to packages/dom-ready/src/test/index.test.ts index dc1fcb882fc4f2..8020d855e0244c 100644 --- a/packages/dom-ready/src/test/index.test.js +++ b/packages/dom-ready/src/test/index.test.ts @@ -14,6 +14,7 @@ describe( 'domReady', () => { describe( 'when document readystate is complete', () => { it( 'should call the callback.', () => { const callback = jest.fn( () => {} ); + // @ts-expect-error document.readyState is read-only document.readyState = 'complete'; domReady( callback ); expect( callback ).toHaveBeenCalled(); @@ -23,6 +24,7 @@ describe( 'domReady', () => { describe( 'when document readystate is interactive', () => { it( 'should call the callback.', () => { const callback = jest.fn( () => {} ); + // @ts-expect-error document.readyState is read-only document.readyState = 'interactive'; domReady( callback ); expect( callback ).toHaveBeenCalled(); @@ -32,6 +34,7 @@ describe( 'domReady', () => { describe( 'when document readystate is still loading', () => { it( 'should add the callback as an event listener to the DOMContentLoaded event.', () => { const addEventListener = jest.fn( () => {} ); + // @ts-expect-error document.readyState is read-only document.readyState = 'loading'; Object.defineProperty( document, 'addEventListener', { value: addEventListener,