From f364e423e06ff6e0200fac562e190a822a131c83 Mon Sep 17 00:00:00 2001 From: Andrew Luca Date: Mon, 9 Sep 2019 21:19:01 +0300 Subject: [PATCH] style(redux-api-middleware): improve generics names (#38154) --- types/redux-api-middleware/index.d.ts | 47 ++++++++++--------- .../redux-api-middleware-tests.ts | 4 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/types/redux-api-middleware/index.d.ts b/types/redux-api-middleware/index.d.ts index abb350f5f4..76973c993c 100644 --- a/types/redux-api-middleware/index.d.ts +++ b/types/redux-api-middleware/index.d.ts @@ -13,13 +13,14 @@ import { applyMiddleware } from 'redux'; +type TypeOrResolver = Type | ((arg: Arg) => Type); + /** * This module is also a UMD module that exposes a global variable 'ReduxApiMiddleware' * when loaded outside a module loader environment. */ export as namespace ReduxApiMiddleware; -export type RSAA = '@@redux-api-middleware/RSAA'; export const RSAA = '@@redux-api-middleware/RSAA'; export function isRSAA(action: object): boolean; @@ -56,7 +57,7 @@ export class ApiError extends Error { export function getJSON(res: Response): Promise | Promise; -export const apiMiddleware: Middleware; +export function apiMiddleware(api: MiddlewareAPI): ReturnType; export interface CreateMiddlewareOptions { ok?: (res: Response) => boolean; @@ -65,41 +66,43 @@ export interface CreateMiddlewareOptions { export function createMiddleware(options?: CreateMiddlewareOptions): Middleware; -export interface RSAARequestTypeDescriptor { +export interface RSAARequestTypeDescriptor { type: string | symbol; - payload?: ((action: RSAAAction, state: S) => P) | P; - meta?: ((action: RSAAAction, state: S) => M) | M; + payload?: ((action: RSAAAction, state: State) => Payload) | Payload; + meta?: ((action: RSAAAction, state: State) => Meta) | Meta; } -export interface RSAASuccessTypeDescriptor { +export interface RSAASuccessTypeDescriptor { type: string | symbol; - payload?: ((action: RSAAAction, state: S, res: any) => P) | P; - meta?: ((action: RSAAAction, state: S, res: any) => M) | M; + payload?: ((action: RSAAAction, state: State, res: any) => Payload) | Payload; + meta?: ((action: RSAAAction, state: State, res: any) => Meta) | Meta; } -export interface RSAAFailureTypeDescriptor { +export interface RSAAFailureTypeDescriptor { type: string | symbol; - payload?: ((action: RSAAAction, state: S) => P) | P; - meta?: ((action: RSAAAction, state: S, res: any) => M) | M; + payload?: ((action: RSAAAction, state: State) => Payload) | Payload; + meta?: ((action: RSAAAction, state: State, res: any) => Meta) | Meta; } -export interface RSAACall { - endpoint: ((state: S) => string) | string; +export interface RSAACall { + endpoint: TypeOrResolver; method: string; types: [ - string | symbol | RSAARequestTypeDescriptor, - string | symbol | RSAASuccessTypeDescriptor, - string | symbol | RSAAFailureTypeDescriptor + string | symbol | RSAARequestTypeDescriptor, + string | symbol | RSAASuccessTypeDescriptor, + string | symbol | RSAAFailureTypeDescriptor ]; - body?: ((state: S) => BodyInit | null) | BodyInit | null; - headers?: ((state: S) => HeadersInit) | HeadersInit; - options?: ((state: S) => RequestInit) | RequestInit; + body?: TypeOrResolver; + headers?: TypeOrResolver; + options?: TypeOrResolver; credentials?: RequestCredentials; - bailout?: ((state: S) => boolean) | boolean; + bailout?: TypeOrResolver; fetch?: typeof fetch; ok?: (res: Response) => boolean; } -export interface RSAAAction { - [RSAA]: RSAACall; +export interface RSAAAction { + [RSAA]: RSAACall; } + +export {}; diff --git a/types/redux-api-middleware/redux-api-middleware-tests.ts b/types/redux-api-middleware/redux-api-middleware-tests.ts index a6a53e7f40..c063791956 100644 --- a/types/redux-api-middleware/redux-api-middleware-tests.ts +++ b/types/redux-api-middleware/redux-api-middleware-tests.ts @@ -16,8 +16,8 @@ import { { // RSAA - const passRSAA: RSAA = '@@redux-api-middleware/RSAA'; - const failRSAA: RSAA = '@@redux-api-middleware/RSAA-fail'; // $ExpectError + const passRSAA: typeof RSAA = '@@redux-api-middleware/RSAA'; + const failRSAA: typeof RSAA = '@@redux-api-middleware/RSAA-fail'; // $ExpectError } {