From 65e876be562ba08b325228df676ba593edd694fc Mon Sep 17 00:00:00 2001 From: Tommy Malone Date: Mon, 18 Sep 2023 14:07:58 -0400 Subject: [PATCH 1/2] Adding bigint to Value type --- packages/@react-facet/core/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@react-facet/core/src/types.ts b/packages/@react-facet/core/src/types.ts index 9d08853c..fe1d8231 100644 --- a/packages/@react-facet/core/src/types.ts +++ b/packages/@react-facet/core/src/types.ts @@ -11,7 +11,7 @@ export interface EqualityCheck { * Currently functions are not supported */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type Value = string | number | boolean | undefined | null | [] | Record +export type Value = string | number | boolean | undefined | null | [] | Record | bigint export type ExtractFacetValues>> = { [K in keyof T]: T[K] extends Facet ? V : never From 3e1f151898d0b7c12ed8431799e8ce5df04a24f2 Mon Sep 17 00:00:00 2001 From: Tommy Malone Date: Mon, 25 Sep 2023 14:07:52 -0400 Subject: [PATCH 2/2] After updating to TS 5.1.3 the behavior of type inference of array types looks to have changed. Previously the types of a useFacetMap for example would look like so: After 5.1.3 the types look like so: The selector arguments are infered as the union of the types of all passed in Facets, rather than each arguments type corresponding to their Facet's inner type. This change fixes that issue by explicitly making the array type we were previously extending into a tuple type. This allows TS to correctly infer the arguments' types. --- packages/@react-facet/core/src/helpers/multiObserve.ts | 2 +- packages/@react-facet/core/src/hooks/useFacetCallback.ts | 6 +++--- packages/@react-facet/core/src/hooks/useFacetEffect.tsx | 2 +- packages/@react-facet/core/src/hooks/useFacetMap.ts | 2 +- packages/@react-facet/core/src/hooks/useFacetMemo.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/@react-facet/core/src/helpers/multiObserve.ts b/packages/@react-facet/core/src/helpers/multiObserve.ts index 067e52d7..f68635ca 100644 --- a/packages/@react-facet/core/src/helpers/multiObserve.ts +++ b/packages/@react-facet/core/src/helpers/multiObserve.ts @@ -10,7 +10,7 @@ import { Facet, Unsubscribe, Cleanup, NO_VALUE, ExtractFacetValues } from '../ty * We pass the dependencies of the callback as the second argument so we can leverage the eslint-plugin-react-hooks option for additionalHooks. * Having this as the second argument allows the linter to work. */ -export function multiObserve[], T extends [...Y]>( +export function multiObserve, ...Facet[]], T extends [...Y]>( effect: (...args: ExtractFacetValues) => void | Cleanup, facets: T, ) { diff --git a/packages/@react-facet/core/src/hooks/useFacetCallback.ts b/packages/@react-facet/core/src/hooks/useFacetCallback.ts index 9b1d2a6a..a0b798a0 100644 --- a/packages/@react-facet/core/src/hooks/useFacetCallback.ts +++ b/packages/@react-facet/core/src/hooks/useFacetCallback.ts @@ -13,7 +13,7 @@ import { Facet, NO_VALUE, ExtractFacetValues, NoValue } from '../types' * We pass the dependencies of the callback as the second argument so we can leverage the eslint-plugin-react-hooks option for additionalHooks. * Having this as the second argument allows the linter to work. */ -export function useFacetCallback[], T extends [...Y], K extends [...unknown[]]>( +export function useFacetCallback, ...Facet[]], T extends [...Y], K extends [...unknown[]]>( callback: (...args: ExtractFacetValues) => (...args: K) => M, dependencies: unknown[], facets: T, @@ -31,13 +31,13 @@ export function useFacetCallback[], T extends [...Y] * We pass the dependencies of the callback as the second argument so we can leverage the eslint-plugin-react-hooks option for additionalHooks. * Having this as the second argument allows the linter to work. */ -export function useFacetCallback[], T extends [...Y], K extends [...unknown[]]>( +export function useFacetCallback, ...Facet[]], T extends [...Y], K extends [...unknown[]]>( callback: (...args: ExtractFacetValues) => (...args: K) => M, dependencies: unknown[], facets: T, ): (...args: K) => M | NoValue -export function useFacetCallback[], T extends [...Y], K extends [...unknown[]]>( +export function useFacetCallback, ...Facet[]], T extends [...Y], K extends [...unknown[]]>( callback: (...args: ExtractFacetValues) => (...args: K) => M, dependencies: unknown[], facets: T, diff --git a/packages/@react-facet/core/src/hooks/useFacetEffect.tsx b/packages/@react-facet/core/src/hooks/useFacetEffect.tsx index 623fa27f..6693aa4e 100644 --- a/packages/@react-facet/core/src/hooks/useFacetEffect.tsx +++ b/packages/@react-facet/core/src/hooks/useFacetEffect.tsx @@ -3,7 +3,7 @@ import { Facet, Unsubscribe, Cleanup, NO_VALUE, ExtractFacetValues } from '../ty import { cancelScheduledTask, scheduleTask } from '../scheduler' export const createUseFacetEffect = (useHook: typeof useEffect | typeof useLayoutEffect) => { - return function [], T extends [...Y]>( + return function , ...Facet[]], T extends [...Y]>( effect: (...args: ExtractFacetValues) => void | Cleanup, dependencies: unknown[], facets: T, diff --git a/packages/@react-facet/core/src/hooks/useFacetMap.ts b/packages/@react-facet/core/src/hooks/useFacetMap.ts index dc179b9c..f428f5bf 100644 --- a/packages/@react-facet/core/src/hooks/useFacetMap.ts +++ b/packages/@react-facet/core/src/hooks/useFacetMap.ts @@ -16,7 +16,7 @@ import { EqualityCheck, Facet, NoValue, ExtractFacetValues } from '../types' * * @returns a new facet definition that can be consumed as a regular facet */ -export function useFacetMap[], T extends [...Y]>( +export function useFacetMap, ...Facet[]], T extends [...Y]>( selector: (...args: ExtractFacetValues) => M | NoValue, dependencies: unknown[], facets: T, diff --git a/packages/@react-facet/core/src/hooks/useFacetMemo.ts b/packages/@react-facet/core/src/hooks/useFacetMemo.ts index f498b5a3..5563f2e2 100644 --- a/packages/@react-facet/core/src/hooks/useFacetMemo.ts +++ b/packages/@react-facet/core/src/hooks/useFacetMemo.ts @@ -16,7 +16,7 @@ import { EqualityCheck, Facet, NoValue, ExtractFacetValues } from '../types' * * @returns a new facet definition that can be consumed as a regular facet */ -export function useFacetMemo[], T extends [...Y]>( +export function useFacetMemo, ...Facet[]], T extends [...Y]>( selector: (...args: ExtractFacetValues) => M | NoValue, dependencies: unknown[], facets: T,