Skip to content

Commit

Permalink
refactor(tsd): use Interface Function Type so that egg-mock can exten…
Browse files Browse the repository at this point in the history
…ds this; (#42)
  • Loading branch information
paranoidjk authored and fengmk2 committed Aug 8, 2018
1 parent 364020a commit 6a84a0a
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions index.d.ts
@@ -1,77 +1,73 @@
declare function mm(target: any, key: string, prop: any): void;

declare namespace mm {
export type Request = (
url: string | RegExp | { url: string, host: string},
data: any,
headers?: object,
delay?: number,
) => MockMate;

export type RequestError = (
url: string | RegExp | { url: string, host: string},
reqError: string | Error,
resError: string | Error,
delay?: number
) => MockMate;

export interface MockMate {
(target: any, key: string, prop: any): void;
/**
* Mock async function error.
*/
function error(mod: any, method: string, error?: string | Error, props?: object, timeout?: number): typeof mm;
error: (mod: any, method: string, error?: string | Error, props?: object, timeout?: number) => MockMate;

/**
* mock return callback(null, data).
*/
function data(mod: any, method: string, data: any, timeout?: number): typeof mm;
data: (mod: any, method: string, data: any, timeout?: number) => MockMate;

/**
* mock return callback(null, null).
*/
function empty(mod: any, method: string, timeout?: number): typeof mm;
empty: (mod: any, method: string, timeout?: number) => MockMate;

/**
* mock return callback(null, data1, data2).
*/
function datas(mod: any, method: string, datas: any, timeout?: number): typeof mm;
datas: (mod: any, method: string, datas: any, timeout?: number) => MockMate;

/**
* mock function sync throw error
*/
function syncError(mod: any, method: string, error?: string | Error, props?: object): void;
syncError: (mod: any, method: string, error?: string | Error, props?: object) => void;

/**
* mock function sync return data
*/
function syncData(mod: any, method: string, data?: any): void;
syncData: (mod: any, method: string, data?: any) => void;

/**
* mock function sync return nothing
*/
function syncEmpty(mod: any, method: string): void;
syncEmpty: (mod: any, method: string) => void;

/**
* remove all mock effects.
*/
function restore(): typeof mm;
restore: () => MockMate;

const http: {
request: (
url: string | RegExp | { url: string, host: string},
data: any,
headers?: object,
delay?: number,
) => typeof mm,
requestError: (
url: string | RegExp | { url: string, host: string},
reqError: string | Error,
resError: string | Error,
delay?: number
) => typeof mm,
}
http: {
request: Request;
requestError: RequestError,
};

const https: {
request: (
url: string | RegExp | { url: string, host: string},
data: any,
headers?: object,
delay?: number,
) => typeof mm,
requestError: (
url: string | RegExp | { url: string, host: string},
reqError: string | Error,
resError: string | Error,
delay?: number
) => typeof mm,
}
https: {
request: Request;
requestError: RequestError,
};

}

declare const mm: MockMate;
export = mm;

This comment has been minimized.

Copy link
@czy88840616

czy88840616 Aug 27, 2018

image

image

这句有点问题,编译不过去。 ts 2.8.0

This comment has been minimized.

Copy link
@fengmk2

fengmk2 Aug 27, 2018

Member

来 pr 修复掉

This comment has been minimized.

Copy link
@atian25

atian25 Aug 27, 2018

Member

This comment has been minimized.

Copy link
@whxaxes

whxaxes Aug 27, 2018

Contributor

#43

export default mm;

0 comments on commit 6a84a0a

Please sign in to comment.