Skip to content

Commit

Permalink
test: add extra keys response body type
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Mar 25, 2024
1 parent e5fa36e commit 78ec30b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/typings/http.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,37 @@ it('supports narrow object as a response body generic argument', () => {
})
})

it('supports object with extra keys as a response body generic argument', () => {
type ResponseBody = {
[key: string]: number | string
id: 123
}

http.get<never, never, ResponseBody>('/user', () => {
return HttpResponse.json({
id: 123,
// Extra keys are allowed if they satisfy the index signature.
name: 'John',
})
})

http.get<never, never, ResponseBody>('/user', () => {
return HttpResponse.json({
// @ts-expect-error Must be 123.
id: 456,
name: 'John',
})
})

http.get<never, never, ResponseBody>('/user', () => {
return HttpResponse.json({
id: 123,
// @ts-expect-error Must satisfy the index signature.
name: { a: 1 },
})
})
})

it('supports response body generic declared via type', () => {
type ResponseBodyType = { id: number }
http.get<never, never, ResponseBodyType>('/user', () => {
Expand Down

0 comments on commit 78ec30b

Please sign in to comment.