From a5dc4980fd7881e15647a9a393a72a8ec3f42a4f Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Tue, 22 Mar 2022 12:04:25 -0700 Subject: [PATCH 1/2] Core data: Fix minor type issue in onSubKey Part of #39211 The `Function` type in `onSubKey` caused an issue when enabling TypeScript for the `core-data` module (when analyzing JS files) because it's not a callable interface. In this patch we're creating a transition type `AnyFunction` and using that as the type in `onSubKey` to remove the type error. After enabling TypeScript for the module we'll be able to provide better types on the function directly, but for now this prevents raising an error. We want to do great things with the `core-data` type system but all of these little nuisances get in the way when we're trying to study those things in isolation. This is a preparatory change to eliminate some of the noise in the existing types. As a type-only change this will have no impact on the built code. Please audit the types and the introduction of the `types.ts` where we import an actual TypeScript type into JSDoc through `@typedef`. Note that this change doesn't "fully-type" `onSubKey` in the sense that it provides full inference for the passed-through reducer. The goal is merely to avoid creating type errors when activating TypeScript across the module. --- packages/core-data/src/types.ts | 3 +++ packages/core-data/src/utils/on-sub-key.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/core-data/src/types.ts diff --git a/packages/core-data/src/types.ts b/packages/core-data/src/types.ts new file mode 100644 index 00000000000000..c718c687c7f562 --- /dev/null +++ b/packages/core-data/src/types.ts @@ -0,0 +1,3 @@ +export interface AnyFunction { + (...args: any[]): any; +} diff --git a/packages/core-data/src/utils/on-sub-key.js b/packages/core-data/src/utils/on-sub-key.js index 24adf06b773ebc..c867187f822c3a 100644 --- a/packages/core-data/src/utils/on-sub-key.js +++ b/packages/core-data/src/utils/on-sub-key.js @@ -1,10 +1,12 @@ +/** @typedef {import('../types').AnyFunction} AnyFunction */ + /** * Higher-order reducer creator which creates a combined reducer object, keyed * by a property on the action object. * * @param {string} actionProperty Action property by which to key object. * - * @return {Function} Higher-order reducer. + * @return {AnyFunction} Higher-order reducer. */ export const onSubKey = ( actionProperty ) => ( reducer ) => ( state = {}, From fa053d5cbdc47ca8fe2d6841e4c0edce93b33506 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Tue, 22 Mar 2022 12:17:46 -0700 Subject: [PATCH 2/2] fixup! Core data: Fix minor type issue in onSubKey --- packages/core-data/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/types.ts b/packages/core-data/src/types.ts index c718c687c7f562..b1664d8ab8dbf7 100644 --- a/packages/core-data/src/types.ts +++ b/packages/core-data/src/types.ts @@ -1,3 +1,3 @@ export interface AnyFunction { - (...args: any[]): any; + ( ...args: any[] ): any; }