Skip to content

Commit

Permalink
types: using generic type for request json parser (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanium authored Aug 11, 2020
1 parent 8a6d6ed commit 68fdf5a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ declare namespace LightMyRequest {
trailers: { [key: string]: string }
payload: string
body: string
json: () => any
json: <T = any>() => T
cookies: Array<object>
}

Expand Down
3 changes: 3 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ type ParsedValue = { field: string }
const response: Response = await inject(dispatch)
const parsedValue: ParsedValue = response.json()
expectType<ParsedValue>(parsedValue)

const parsedValueUsingGeneric = response.json<ParsedValue>()
expectType<ParsedValue>(parsedValueUsingGeneric)

0 comments on commit 68fdf5a

Please sign in to comment.