/*
 * Author: yuanzhirong
 * Date: 2020-11-24 15:19:27
 * @LastEditors: yuanzhirong
 * @LastEditTime: 2021-01-28 16:55:04
 * Description:
 */

/**
 * 可选查询参数的函数定义，一般结合 hooks 定义查询数据的函数
 * @example
 *
 * const getDiagnosesList = React.useCallback<OptionalQueryParamsMethod<State>>(
 *  async query => {
 *    const finalQuery = { ...state.query, ...query } // 合并搜索条件
 *    const result = await fetch(finalQuery)
 *  },
 * [state, store, setState]
 * )
 */

declare type OptionalParamsMethod<S extends AnyObject, R = Promise<void>> = <
  K extends keyof S,
>(
  state?: Pick<S, K>,
) => R;
/**
 * webpack 环境变量
 */
declare namespace NodeJS {
  interface ProcessEnv {
    NODE_ENV: 'development' | 'production';
  }
}

/** 任意 key-value 形式的对象 */
declare interface AnyObject<T = any> {
  [k: string]: T;
}

/** 定义类似 React.setState 函数声明 */
declare type SetStateLikeMethod<S extends AnyObject> = <K extends keyof S>(
  state: Pick<S, K> | ((state: Readonly<S>) => Pick<S, K> | S | null),
) => void;
