Skip to content

Commit b62ee71

Browse files
committed
infer arg type when only header or cookie parameter is present - fixes #13
1 parent 49d1451 commit b62ee71

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type OpArgType<OP> = OP extends {
1818
path?: infer P
1919
query?: infer Q
2020
body?: infer B
21+
header?: unknown // ignore
22+
cookie?: unknown // ignore
2123
}
2224
// openapi 3
2325
requestBody?: {

test/infer.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ describe('infer', () => {
9797
expect(same).toBe(true)
9898
})
9999

100+
it('only header/cookie parameter with requestBody', () => {
101+
type RequestBody = {
102+
requestBody: {
103+
content: {
104+
'application/json': { bar: boolean }
105+
}
106+
}
107+
}
108+
109+
type HeaderOnly = {
110+
parameters: {
111+
header: { foo: string }
112+
}
113+
} & RequestBody
114+
115+
type CookieOnly = {
116+
parameters: {
117+
cookie: { foo: string }
118+
}
119+
} & RequestBody
120+
121+
const header: Same<OpArgType<HeaderOnly>, { bar: boolean }> = true
122+
const cookie: Same<OpArgType<CookieOnly>, { bar: boolean }> = true
123+
124+
expect(header).toBe(true)
125+
expect(cookie).toBe(true)
126+
})
127+
100128
const err: Err = { data: { error: {} } } as any
101129
expect(err.data.error.charge).toBeUndefined()
102130
})

0 commit comments

Comments
 (0)