From 4315de6a3a79b7237fdc5f1dee24151cdce110a4 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 1 Nov 2024 11:37:24 +0530 Subject: [PATCH 1/3] Convert private-apis package to TypeScript --- .../{implementation.js => implementation.ts} | 24 +++++++++---------- .../private-apis/src/{index.js => index.ts} | 0 2 files changed, 11 insertions(+), 13 deletions(-) rename packages/private-apis/src/{implementation.js => implementation.ts} (90%) rename packages/private-apis/src/{index.js => index.ts} (100%) diff --git a/packages/private-apis/src/implementation.js b/packages/private-apis/src/implementation.ts similarity index 90% rename from packages/private-apis/src/implementation.js rename to packages/private-apis/src/implementation.ts index b32a95986d32c9..7206703692783e 100644 --- a/packages/private-apis/src/implementation.js +++ b/packages/private-apis/src/implementation.ts @@ -2,7 +2,7 @@ * wordpress/private-apis – the utilities to enable private cross-package * exports of private APIs. * - * This "implementation.js" file is needed for the sake of the unit tests. It + * This "implementation.ts" file is needed for the sake of the unit tests. It * exports more than the public API of the package to aid in testing. */ @@ -36,10 +36,8 @@ const CORE_MODULES_USING_PRIVATE_APIS = [ /** * A list of core modules that already opted-in to * the privateApis package. - * - * @type {string[]} */ -const registeredPrivateApis = []; +const registeredPrivateApis: Array< string > = []; /* * Warning for theme and plugin developers. @@ -70,8 +68,8 @@ const allowReRegistration = globalThis.IS_WORDPRESS_CORE ? false : true; * @return {{lock: typeof lock, unlock: typeof unlock}} An object containing the lock and unlock functions. */ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( - consent, - moduleName + consent: string, + moduleName: string ) => { if ( ! CORE_MODULES_USING_PRIVATE_APIS.includes( moduleName ) ) { throw new Error( @@ -135,10 +133,10 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( * // { a: 1 } * ``` * - * @param {any} object The object to bind the private data to. - * @param {any} privateData The private data to bind to the object. + * @param {Record< symbol, WeakKey >} object The object to bind the private data to. + * @param {unknown} privateData The private data to bind to the object. */ -function lock( object, privateData ) { +function lock( object: Record< symbol, WeakKey >, privateData: unknown ) { if ( ! object ) { throw new Error( 'Cannot lock an undefined object.' ); } @@ -168,10 +166,10 @@ function lock( object, privateData ) { * // { a: 1 } * ``` * - * @param {any} object The object to unlock the private data from. - * @return {any} The private data bound to the object. + * @param {Record< symbol, WeakKey >} object The object to unlock the private data from. + * @return {unknown} The private data bound to the object. */ -function unlock( object ) { +function unlock( object: Record< symbol, WeakKey > ) { if ( ! object ) { throw new Error( 'Cannot unlock an undefined object.' ); } @@ -200,7 +198,7 @@ const __private = Symbol( 'Private API ID' ); * * @param {string} name The name of the module. */ -export function allowCoreModule( name ) { +export function allowCoreModule( name: string ) { CORE_MODULES_USING_PRIVATE_APIS.push( name ); } diff --git a/packages/private-apis/src/index.js b/packages/private-apis/src/index.ts similarity index 100% rename from packages/private-apis/src/index.js rename to packages/private-apis/src/index.ts From aad9c54500b5071b8fe986938980b80b593e0cfe Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 1 Nov 2024 11:47:27 +0530 Subject: [PATCH 2/3] Convert the usage of private-apis to TypeScript --- packages/block-editor/src/{lock-unlock.js => lock-unlock.ts} | 0 packages/block-library/src/{lock-unlock.js => lock-unlock.ts} | 0 packages/core-data/src/{lock-unlock.js => lock-unlock.ts} | 0 packages/data/src/{lock-unlock.js => lock-unlock.ts} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename packages/block-editor/src/{lock-unlock.js => lock-unlock.ts} (100%) rename packages/block-library/src/{lock-unlock.js => lock-unlock.ts} (100%) rename packages/core-data/src/{lock-unlock.js => lock-unlock.ts} (100%) rename packages/data/src/{lock-unlock.js => lock-unlock.ts} (100%) diff --git a/packages/block-editor/src/lock-unlock.js b/packages/block-editor/src/lock-unlock.ts similarity index 100% rename from packages/block-editor/src/lock-unlock.js rename to packages/block-editor/src/lock-unlock.ts diff --git a/packages/block-library/src/lock-unlock.js b/packages/block-library/src/lock-unlock.ts similarity index 100% rename from packages/block-library/src/lock-unlock.js rename to packages/block-library/src/lock-unlock.ts diff --git a/packages/core-data/src/lock-unlock.js b/packages/core-data/src/lock-unlock.ts similarity index 100% rename from packages/core-data/src/lock-unlock.js rename to packages/core-data/src/lock-unlock.ts diff --git a/packages/data/src/lock-unlock.js b/packages/data/src/lock-unlock.ts similarity index 100% rename from packages/data/src/lock-unlock.js rename to packages/data/src/lock-unlock.ts From 3de632470c0723327fdd63c72c063a6a3814cbfe Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 1 Nov 2024 16:15:06 +0530 Subject: [PATCH 3/3] Clean up JSDoc --- packages/private-apis/src/implementation.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/private-apis/src/implementation.ts b/packages/private-apis/src/implementation.ts index 7206703692783e..ee2b9693959a35 100644 --- a/packages/private-apis/src/implementation.ts +++ b/packages/private-apis/src/implementation.ts @@ -63,9 +63,9 @@ const allowReRegistration = globalThis.IS_WORDPRESS_CORE ? false : true; * Called by a @wordpress package wishing to opt-in to accessing or exposing * private private APIs. * - * @param {string} consent The consent string. - * @param {string} moduleName The name of the module that is opting in. - * @return {{lock: typeof lock, unlock: typeof unlock}} An object containing the lock and unlock functions. + * @param consent The consent string. + * @param moduleName The name of the module that is opting in. + * @return An object containing the lock and unlock functions. */ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( consent: string, @@ -133,8 +133,8 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = ( * // { a: 1 } * ``` * - * @param {Record< symbol, WeakKey >} object The object to bind the private data to. - * @param {unknown} privateData The private data to bind to the object. + * @param object The object to bind the private data to. + * @param privateData The private data to bind to the object. */ function lock( object: Record< symbol, WeakKey >, privateData: unknown ) { if ( ! object ) { @@ -166,8 +166,8 @@ function lock( object: Record< symbol, WeakKey >, privateData: unknown ) { * // { a: 1 } * ``` * - * @param {Record< symbol, WeakKey >} object The object to unlock the private data from. - * @return {unknown} The private data bound to the object. + * @param object The object to unlock the private data from. + * @return The private data bound to the object. */ function unlock( object: Record< symbol, WeakKey > ) { if ( ! object ) { @@ -196,7 +196,7 @@ const __private = Symbol( 'Private API ID' ); * Private function to allow the unit tests to allow * a mock module to access the private APIs. * - * @param {string} name The name of the module. + * @param name The name of the module. */ export function allowCoreModule( name: string ) { CORE_MODULES_USING_PRIVATE_APIS.push( name );