Typescript声明

namespace相当于给一个对象添加属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

declare const jQuery: (sel: string) => any;

type HttpMethods = 'GET' | 'POST';
declare function Fetch<T = any>(url: string, method: HttpMethods, data?: any): Promise<T>

// 相当于给Fetch对象添加属性
declare namespace Fetch {
const get: <T = any> (url: string) => Promise<T>
const post: <T = any> (url: string, data: any) => Promise<T>
}

export {
jQuery,
Fetch
}