Skip to content

Commit b11b959

Browse files
committed
fix: wrong type of .query/.set/.params
1 parent e9a5c26 commit b11b959

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/keq.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { KeqQueryValue } from './types/keq-query-value.js'
2020
import type { KeqResolveMethod } from './types/keq-resolve-with-mode.js'
2121
import type { CommonContentType, ShorthandContentType } from './types/content-type.js'
2222
import type { KeqContextOptions } from './types/keq-context.js'
23-
import type { ExtractFields, ExtractFiles, ExtractHeaders, ExtractParams, ExtractQuery, KeqBaseOperation, KeqOperation } from './types/keq-operation.js'
23+
import type { ExtractFields, ExtractFiles, KeqBaseOperation, KeqOperation } from './types/keq-operation.js'
2424
import type { KeqContextRequestBody } from './types/keq-context-request.js'
2525
import { isValidHeaderValue } from './util/is-valid-header-value.js'
2626
import { isReadableStream } from './is/is-readable-stream.js'
@@ -58,14 +58,14 @@ export class Keq<
5858
*
5959
* @description 设置请求头
6060
*/
61-
set(headers: ExtractHeaders<OPERATION>): this
62-
set<T extends keyof ExtractHeaders<OPERATION>>(name: T, value: ExtractHeaders<OPERATION>[T]): this
61+
set(headers: OPERATION['requestHeaders']): this
62+
set<T extends keyof OPERATION['requestHeaders']>(name: T, value: OPERATION['requestHeaders'][T]): this
6363
set<T extends keyof KeqBaseOperation['requestHeaders']>(name: T, value: KeqBaseOperation['requestHeaders'][T]): this
6464
set(headers: Headers): this
6565
set(headers: Record<string, string>): this
6666
set(name: string, value: string | number): this
6767
set(
68-
headersOrName: ExtractHeaders<OPERATION> | KeqOperation['requestHeaders'] | string | Record<string, string> | Headers,
68+
headersOrName: OPERATION['requestHeaders'] | KeqOperation['requestHeaders'] | string | Record<string, string> | Headers,
6969
value?: string | number,
7070
): this {
7171
if (isHeaders(headersOrName)) {
@@ -94,11 +94,11 @@ export class Keq<
9494
/**
9595
* Set request query/searchParams
9696
*/
97-
query(key: ExtractQuery<OPERATION>): this
98-
query<T extends keyof ExtractQuery<OPERATION>>(key: T, value: ExtractQuery<OPERATION>[T]): this
97+
query(key: OPERATION['requestQuery']): this
98+
query<T extends keyof OPERATION['requestQuery']>(key: T, value: OPERATION['requestQuery'][T]): this
9999
query(key: Record<string, KeqQueryValue | KeqQueryValue[]>): this
100100
query(key: string, value: KeqQueryValue | KeqQueryValue[]): this
101-
query(key: string | ExtractQuery<OPERATION> | Record<string, KeqQueryValue | KeqQueryValue[]>, value?: KeqQueryValue | KeqQueryValue[]): this {
101+
query(key: string | OPERATION['requestQuery'] | Record<string, KeqQueryValue | KeqQueryValue[]>, value?: KeqQueryValue | KeqQueryValue[]): this {
102102
if (typeof key === 'object') {
103103
for (const [k, v] of Object.entries(key)) {
104104
if (v === undefined) continue
@@ -129,11 +129,11 @@ export class Keq<
129129
/**
130130
* Set request route params
131131
*/
132-
params(key: ExtractParams<OPERATION>): this
133-
params<T extends keyof ExtractParams<OPERATION>>(key: T, value: ExtractParams<OPERATION>[T]): this
132+
params(key: OPERATION['requestParams']): this
133+
params<T extends keyof OPERATION['requestParams']>(key: T, value: OPERATION['requestParams'][T]): this
134134
params(key: Record<string, string | number>): this
135135
params(key: string, value: string | number): this
136-
params(key: string | ExtractParams<OPERATION> | Record<string, string | number>, value?: string | number): this {
136+
params(key: string | OPERATION['requestParams'] | Record<string, string | number>, value?: string | number): this {
137137
if (typeof key === 'string') {
138138
this.requestContext.routeParams[key] = String(value)
139139
} else if (typeof key === 'object') {

src/types/keq-operation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export interface KeqOperation {
2121
responseBody: any
2222
}
2323

24-
export type ExtractHeaders<T extends Pick<KeqOperation, 'requestHeaders'>> = ExtractProperty<T['requestHeaders'], string>
25-
export type ExtractQuery<T extends Pick<KeqOperation, 'requestQuery'>> = ExtractProperty<T['requestQuery'], string | string[]>
26-
export type ExtractParams<T extends Pick<KeqOperation, 'requestParams'>> = ExtractProperty<T['requestParams'], string>
2724
export type ExtractFields<T extends Pick<KeqOperation, 'requestBody'>> = ExtractProperty<Exclude<Extract<T['requestBody'], object>, FormData | URLSearchParams | Array<any>>, string>
2825
export type ExtractFiles<T extends Pick<KeqOperation, 'requestBody'>> = ExtractProperty<Exclude<Extract<T['requestBody'], object>, FormData | URLSearchParams | Array<any>>, Buffer | Blob | File>
2926

0 commit comments

Comments
 (0)