Skip to content

Commit

Permalink
Make JSON phin generic
Browse files Browse the repository at this point in the history
  • Loading branch information
LuminescentMoon committed Feb 5, 2019
1 parent 2155b3e commit 2ad0b10
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IOptionsBase {
path?: string
}

// Form and data property has been written this way so they're mutually exclusive.
type IWithData<T extends {}> = T & {
data: {
toString(): string
Expand All @@ -28,10 +29,10 @@ type IWithForm<T extends {}> = T & {
}
}

declare function phin(options:
declare function phin<T>(options:
phin.IJSONResponseOptions |
IWithData<phin.IJSONResponseOptions> |
IWithForm<phin.IJSONResponseOptions>): Promise<phin.IJSONResponse>
IWithForm<phin.IJSONResponseOptions>): Promise<phin.IJSONResponse<T>>

declare function phin(options:
phin.IStreamResponseOptions |
Expand All @@ -57,8 +58,8 @@ declare namespace phin {
parse?: 'none'
}

export interface IJSONResponse extends http.IncomingMessage {
body: object
export interface IJSONResponse<T> extends http.IncomingMessage {
body: T
}

export interface IStreamResponse extends http.IncomingMessage {
Expand All @@ -76,12 +77,12 @@ declare namespace phin {

export let promisified: typeof phin

export function unpromisified(
export function unpromisified<T>(
options:
IJSONResponseOptions |
IWithData<IJSONResponseOptions> |
IWithForm<IJSONResponseOptions>,
callback: IErrorCallback | ICallback<IJSONResponse>): void
callback: IErrorCallback | ICallback<IJSONResponse<T>>): void

export function unpromisified(
options:
Expand Down

0 comments on commit 2ad0b10

Please sign in to comment.