add d.ts for fetch.io package

This commit is contained in:
newraina
2017-02-21 11:36:52 +08:00
parent 755fad105c
commit 05d4b1ab4c
4 changed files with 170 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
import Fetch from 'fetch.io'
const request = new Fetch()
request
.get('')
.query({})
.json()
request
.delete('')
.json()
request
.head('')
.json()
request
.options('')
.json()
request
.put('')
.json()
request
.config('key', 'value')
.json()
request
.config({key: 'value'})
.json()
request
.config('set', 'value')
.json()
request
.set({key: 'value'})
.json()
request
.type('json')
.json()
request
.get('')
.query({})
.text()
request
.get('')
.query({})
.then(() => {})
request
.post('')
.send({})
.json()
+85
View File
@@ -0,0 +1,85 @@
// Type definitions for fetch.io v3.1.4
// Project: https://github.com/haoxins/fetch.io
// Definitions by: newraina <https://github.com/newraina>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type TUrl = string
type TMethod = 'delete' | 'get' | 'head' | 'options' | 'post' | 'put'
interface IQuery {
[key: string]: number | boolean | string
}
interface IHeader {
[key: string]: string
}
interface IOptions extends RequestInit {
prefix?: string
query?: IQuery
header?: IHeader
beforeRequest?(url: TUrl, body: BodyInit): boolean
afterResponse?(res: Response): void
afterJSON?(body: any): void
}
declare namespace FetchIo {
class Request {
constructor(method: TMethod, url: TUrl, options: IOptions)
delete: (url: TUrl) => this
get: (url: TUrl) => this
head: (url: TUrl) => this
options: (url: TUrl) => this
post: (url: TUrl) => this
put: (url: TUrl) => this
config(key: string, value: any): this
config(opts: {[key: string]: any}): this
set(key: string, value: any): this
set(opts: {[key: string]: any}): this
type(type: 'json' | 'form' | 'urlencoded'): this
query(object: {[key: string]: any}): this
send(data: {[key: string]: any}): this
append(key: string, value: string): this
then(resolve: (value?: Response) => void, reject?: (reason?: any) => void): Promise<any>
then<T>(resolve: (value?: Response) => void, reject?: (reason?: any) => void): Promise<T>
json(strict?: boolean): Promise<any>
json<T>(strict?: boolean): Promise<T>
text(): Promise<string>
text<T>(): Promise<T>
}
class Fetch extends Request {
constructor(options?: IOptions)
}
}
export = FetchIo.Fetch
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"fetch.io-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }