diff --git a/packages/endpoint/src/endpointTypes.ts b/packages/endpoint/src/endpointTypes.ts index db39b833e9c9..c442769239b0 100644 --- a/packages/endpoint/src/endpointTypes.ts +++ b/packages/endpoint/src/endpointTypes.ts @@ -184,10 +184,9 @@ type IfTypeScriptLooseNull = 1 | undefined extends 1 ? Y : N; type OnlyFirst = A extends [] ? [] : [A[0]]; -type RemoveArray = Rem extends ( - [any, ...infer RestRem] -) ? - Orig extends [any, ...infer RestOrig] ? - RemoveArray - : never -: Orig; +type RemoveArray = + Rem extends [any, ...infer RestRem] ? + Orig extends [any, ...infer RestOrig] ? + RemoveArray + : never + : Orig; diff --git a/packages/normalizr/src/endpoint/utility.ts b/packages/normalizr/src/endpoint/utility.ts index 5864b3d84172..b42b041f7c48 100644 --- a/packages/normalizr/src/endpoint/utility.ts +++ b/packages/normalizr/src/endpoint/utility.ts @@ -7,9 +7,7 @@ export type ResolveType any> = ReturnType extends Promise ? R : never; /** Fallback to schema if fetch function isn't defined */ -export type InferReturn< - F extends FetchFunction, - S extends Schema | undefined, -> = S extends undefined ? ReturnType -: ReturnType extends unknown ? Promise> -: ReturnType; +export type InferReturn = + S extends undefined ? ReturnType + : ReturnType extends unknown ? Promise> + : ReturnType; diff --git a/packages/redux/src/prepareStore.tsx b/packages/redux/src/prepareStore.tsx index c146339318d3..5ec87d86c095 100644 --- a/packages/redux/src/prepareStore.tsx +++ b/packages/redux/src/prepareStore.tsx @@ -57,12 +57,13 @@ type ReducersMapObject< S = any, A extends { type: string } = any, PreloadedState = S, -> = keyof PreloadedState extends keyof S ? - { - [K in keyof S]: Reducer< - S[K], - A, - K extends keyof PreloadedState ? PreloadedState[K] : never - >; - } -: never; +> = + keyof PreloadedState extends keyof S ? + { + [K in keyof S]: Reducer< + S[K], + A, + K extends keyof PreloadedState ? PreloadedState[K] : never + >; + } + : never; diff --git a/packages/rest/src/OptionsToFunction.ts b/packages/rest/src/OptionsToFunction.ts index 5fbee484648a..d8597299adf2 100644 --- a/packages/rest/src/OptionsToFunction.ts +++ b/packages/rest/src/OptionsToFunction.ts @@ -7,49 +7,51 @@ export type OptionsToFunction< O extends PartialRestGenerics, E extends { body?: any; path?: string; method?: string }, F extends FetchFunction, -> = 'path' extends keyof O ? - RestFetch< - 'searchParams' extends keyof O ? - O['searchParams'] & PathArgs> - : PathArgs>, - OptionsToBodyArgument< - 'body' extends keyof O ? O : E, - 'method' extends keyof O ? O['method'] : E['method'] - >, - O['process'] extends {} ? ReturnType : ResolveType - > -: 'body' extends keyof O ? - RestFetch< - 'searchParams' extends keyof O ? - O['searchParams'] & PathArgs> - : PathArgs>, - OptionsToBodyArgument< - O, - 'method' extends keyof O ? O['method'] : E['method'] - >, - O['process'] extends {} ? ReturnType : ResolveType - > -: 'searchParams' extends keyof O ? - RestFetch< - O['searchParams'] & PathArgs>, - OptionsToBodyArgument< - E, - 'method' extends keyof O ? O['method'] : E['method'] - >, - O['process'] extends {} ? ReturnType : ResolveType - > -: ( - this: ThisParameterType, - ...args: Parameters - ) => Promise< - O['process'] extends {} ? ReturnType : ResolveType - >; +> = + 'path' extends keyof O ? + RestFetch< + 'searchParams' extends keyof O ? + O['searchParams'] & PathArgs> + : PathArgs>, + OptionsToBodyArgument< + 'body' extends keyof O ? O : E, + 'method' extends keyof O ? O['method'] : E['method'] + >, + O['process'] extends {} ? ReturnType : ResolveType + > + : 'body' extends keyof O ? + RestFetch< + 'searchParams' extends keyof O ? + O['searchParams'] & PathArgs> + : PathArgs>, + OptionsToBodyArgument< + O, + 'method' extends keyof O ? O['method'] : E['method'] + >, + O['process'] extends {} ? ReturnType : ResolveType + > + : 'searchParams' extends keyof O ? + RestFetch< + O['searchParams'] & PathArgs>, + OptionsToBodyArgument< + E, + 'method' extends keyof O ? O['method'] : E['method'] + >, + O['process'] extends {} ? ReturnType : ResolveType + > + : ( + this: ThisParameterType, + ...args: Parameters + ) => Promise< + O['process'] extends {} ? ReturnType : ResolveType + >; export type OptionsToBodyArgument< O extends { body?: any }, Method extends string | undefined, -> = Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' ? - 'body' extends keyof O ? - O['body'] - : any -: undefined; +> = + Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' ? + 'body' extends keyof O ? + O['body'] + : any + : undefined; diff --git a/packages/rest/src/RestEndpointTypes.ts b/packages/rest/src/RestEndpointTypes.ts index 1f3239a9f48f..399443acd425 100644 --- a/packages/rest/src/RestEndpointTypes.ts +++ b/packages/rest/src/RestEndpointTypes.ts @@ -208,89 +208,95 @@ type OptionsToRestEndpoint< O extends PartialRestGenerics, E extends RestInstanceBase & { body?: any; paginationField?: string }, F extends FetchFunction, -> = 'path' extends keyof O ? - RestType< - 'searchParams' extends keyof O ? - O['searchParams'] extends undefined ? - PathArgs> - : O['searchParams'] & PathArgs> - : PathArgs>, - OptionsToBodyArgument< - 'body' extends keyof O ? O : E, - 'method' extends keyof O ? O['method'] : E['method'] - >, - 'schema' extends keyof O ? O['schema'] : E['schema'], - 'method' extends keyof O ? MethodToSide : E['sideEffect'], - O['process'] extends {} ? ReturnType : ResolveType, - { - path: Exclude; - body: 'body' extends keyof O ? O['body'] : E['body']; - searchParams: 'searchParams' extends keyof O ? O['searchParams'] - : E['searchParams']; - method: 'method' extends keyof O ? O['method'] : E['method']; - paginationField: 'paginationField' extends keyof O ? O['paginationField'] - : E['paginationField']; - } - > -: 'body' extends keyof O ? - RestType< - 'searchParams' extends keyof O ? +> = + 'path' extends keyof O ? + RestType< + 'searchParams' extends keyof O ? + O['searchParams'] extends undefined ? + PathArgs> + : O['searchParams'] & PathArgs> + : PathArgs>, + OptionsToBodyArgument< + 'body' extends keyof O ? O : E, + 'method' extends keyof O ? O['method'] : E['method'] + >, + 'schema' extends keyof O ? O['schema'] : E['schema'], + 'method' extends keyof O ? MethodToSide : E['sideEffect'], + O['process'] extends {} ? ReturnType : ResolveType, + { + path: Exclude; + body: 'body' extends keyof O ? O['body'] : E['body']; + searchParams: 'searchParams' extends keyof O ? O['searchParams'] + : E['searchParams']; + method: 'method' extends keyof O ? O['method'] : E['method']; + paginationField: 'paginationField' extends keyof O ? + O['paginationField'] + : E['paginationField']; + } + > + : 'body' extends keyof O ? + RestType< + 'searchParams' extends keyof O ? + O['searchParams'] extends undefined ? + PathArgs> + : O['searchParams'] & PathArgs> + : PathArgs>, + OptionsToBodyArgument< + O, + 'method' extends keyof O ? O['method'] : E['method'] + >, + 'schema' extends keyof O ? O['schema'] : E['schema'], + 'method' extends keyof O ? MethodToSide : E['sideEffect'], + O['process'] extends {} ? ReturnType : ResolveType, + { + path: E['path']; + body: O['body']; + searchParams: 'searchParams' extends keyof O ? O['searchParams'] + : E['searchParams']; + method: 'method' extends keyof O ? O['method'] : E['method']; + paginationField: 'paginationField' extends keyof O ? + O['paginationField'] + : Extract; + } + > + : 'searchParams' extends keyof O ? + RestType< O['searchParams'] extends undefined ? PathArgs> - : O['searchParams'] & PathArgs> - : PathArgs>, - OptionsToBodyArgument< - O, - 'method' extends keyof O ? O['method'] : E['method'] - >, - 'schema' extends keyof O ? O['schema'] : E['schema'], - 'method' extends keyof O ? MethodToSide : E['sideEffect'], - O['process'] extends {} ? ReturnType : ResolveType, - { - path: E['path']; - body: O['body']; - searchParams: 'searchParams' extends keyof O ? O['searchParams'] - : E['searchParams']; - method: 'method' extends keyof O ? O['method'] : E['method']; - paginationField: 'paginationField' extends keyof O ? O['paginationField'] - : Extract; - } - > -: 'searchParams' extends keyof O ? - RestType< - O['searchParams'] extends undefined ? - PathArgs> - : O['searchParams'] & PathArgs>, - OptionsToBodyArgument< - E, - 'method' extends keyof O ? O['method'] : E['method'] - >, - 'schema' extends keyof O ? O['schema'] : E['schema'], - 'method' extends keyof O ? MethodToSide : E['sideEffect'], - O['process'] extends {} ? ReturnType : ResolveType, - { - path: E['path']; - body: E['body']; - searchParams: O['searchParams']; - method: 'method' extends keyof O ? O['method'] : E['method']; - paginationField: 'paginationField' extends keyof O ? O['paginationField'] - : Extract; - } - > -: RestInstance< - F, - 'schema' extends keyof O ? O['schema'] : E['schema'], - 'method' extends keyof O ? MethodToSide : E['sideEffect'], - { - path: 'path' extends keyof O ? Exclude : E['path']; - body: 'body' extends keyof O ? O['body'] : E['body']; - searchParams: 'searchParams' extends keyof O ? O['searchParams'] - : E['searchParams']; - method: 'method' extends keyof O ? O['method'] : E['method']; - paginationField: 'paginationField' extends keyof O ? O['paginationField'] - : E['paginationField']; - } - >; + : O['searchParams'] & PathArgs>, + OptionsToBodyArgument< + E, + 'method' extends keyof O ? O['method'] : E['method'] + >, + 'schema' extends keyof O ? O['schema'] : E['schema'], + 'method' extends keyof O ? MethodToSide : E['sideEffect'], + O['process'] extends {} ? ReturnType : ResolveType, + { + path: E['path']; + body: E['body']; + searchParams: O['searchParams']; + method: 'method' extends keyof O ? O['method'] : E['method']; + paginationField: 'paginationField' extends keyof O ? + O['paginationField'] + : Extract; + } + > + : RestInstance< + F, + 'schema' extends keyof O ? O['schema'] : E['schema'], + 'method' extends keyof O ? MethodToSide : E['sideEffect'], + { + path: 'path' extends keyof O ? Exclude + : E['path']; + body: 'body' extends keyof O ? O['body'] : E['body']; + searchParams: 'searchParams' extends keyof O ? O['searchParams'] + : E['searchParams']; + method: 'method' extends keyof O ? O['method'] : E['method']; + paginationField: 'paginationField' extends keyof O ? + O['paginationField'] + : E['paginationField']; + } + >; export type RestExtendedEndpoint< O extends PartialRestGenerics, @@ -577,8 +583,8 @@ type IfTypeScriptLooseNull = 1 | undefined extends 1 ? Y : N; export type KeyofRestEndpoint = keyof RestInstance; -export type FromFallBack = K extends keyof O ? O[K] -: E[K]; +export type FromFallBack = + K extends keyof O ? O[K] : E[K]; export type FetchMutate< A extends readonly any[] = // eslint-disable-next-line @typescript-eslint/ban-types diff --git a/packages/rest/src/mapCollection.ts b/packages/rest/src/mapCollection.ts index af814866ca92..e7d19d667bfe 100644 --- a/packages/rest/src/mapCollection.ts +++ b/packages/rest/src/mapCollection.ts @@ -33,10 +33,11 @@ export default function mapCollection< type MapCollection< M extends (collection: C) => any, S extends Schema | undefined, -> = S extends schema.Collection ? ReturnType -: S extends schema.Object ? MapCollection -: S extends { [K: string]: any } ? MapObject -: never; +> = + S extends schema.Collection ? ReturnType + : S extends schema.Object ? MapCollection + : S extends { [K: string]: any } ? MapObject + : never; export type MapObject< M extends (collection: schema.Collection) => any,