Skip to content

Commit 2c82b01

Browse files
committed
perf: support stict type checking for .send/.params/.set/.query
1 parent b11b959 commit 2c82b01

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/keq.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
12
/* eslint-disable @typescript-eslint/no-explicit-any */
23
import { Core } from './core.js'
34
import { Exception } from './exception/exception.js'
@@ -58,8 +59,8 @@ export class Keq<
5859
*
5960
* @description 设置请求头
6061
*/
61-
set(headers: OPERATION['requestHeaders']): this
62-
set<T extends keyof OPERATION['requestHeaders']>(name: T, value: OPERATION['requestHeaders'][T]): this
62+
set<K extends 'strict'>(headers: OPERATION['requestHeaders']): this
63+
set<K extends 'strict', T extends keyof OPERATION['requestHeaders']>(name: T, value: OPERATION['requestHeaders'][T]): this
6364
set<T extends keyof KeqBaseOperation['requestHeaders']>(name: T, value: KeqBaseOperation['requestHeaders'][T]): this
6465
set(headers: Headers): this
6566
set(headers: Record<string, string>): this
@@ -94,8 +95,8 @@ export class Keq<
9495
/**
9596
* Set request query/searchParams
9697
*/
97-
query(key: OPERATION['requestQuery']): this
98-
query<T extends keyof OPERATION['requestQuery']>(key: T, value: OPERATION['requestQuery'][T]): this
98+
query<K extends 'strict'>(key: OPERATION['requestQuery']): this
99+
query<K extends 'strict', T extends keyof OPERATION['requestQuery']>(key: T, value: OPERATION['requestQuery'][T]): this
99100
query(key: Record<string, KeqQueryValue | KeqQueryValue[]>): this
100101
query(key: string, value: KeqQueryValue | KeqQueryValue[]): this
101102
query(key: string | OPERATION['requestQuery'] | Record<string, KeqQueryValue | KeqQueryValue[]>, value?: KeqQueryValue | KeqQueryValue[]): this {
@@ -129,8 +130,8 @@ export class Keq<
129130
/**
130131
* Set request route params
131132
*/
132-
params(key: OPERATION['requestParams']): this
133-
params<T extends keyof OPERATION['requestParams']>(key: T, value: OPERATION['requestParams'][T]): this
133+
params<K extends 'strict'>(key: OPERATION['requestParams']): this
134+
params<K extends 'strict', T extends keyof OPERATION['requestParams']>(key: T, value: OPERATION['requestParams'][T]): this
134135
params(key: Record<string, string | number>): this
135136
params(key: string, value: string | number): this
136137
params(key: string | OPERATION['requestParams'] | Record<string, string | number>, value?: string | number): this {
@@ -187,7 +188,8 @@ export class Keq<
187188
/**
188189
* set request body
189190
*/
190-
send(value: OPERATION['requestBody'] | object): this
191+
send<K extends 'strict'>(value: OPERATION['requestBody']): this
192+
send(value: object): this
191193
send(value: FormData): this
192194
send(value: URLSearchParams): this
193195
send(value: Array<any>): this

0 commit comments

Comments
 (0)