export interface Query<Field extends string | number | symbol> {
fields?: Field | Field[]
filters?: {
[p in Field]: string
}
}
interface HttpOptions<Field extends string | number | symbol> {
needAuth?: boolean
query?: Query<Field>
}
export function http<T, Field extends keyof T = keyof T>(
requestOptions: UniApp.RequestOptions,
httpOptions?: HttpOptions<Field>,
) {...}
在使用时,对应的 Tool 有一个 description 字段,但是在输入 des 并不会有类型的提示。
http<Tool>(
{
method: 'GET',
url: '/tools',
},
{
query: {
fields: 'cost',
filters: {
des,
},
},
},
)
如果把上面的代码改写为
export interface Query<T, Field extends keyof T = keyof T> {
fields?: Field | Field[]
filters?: {
[p in Field]: string
}
}
interface HttpOptions<T> {
needAuth?: boolean
query?: Query<T>
}
export function http<T>(requestOptions: UniApp.RequestOptions, httpOptions?: HttpOptions<T>) {...}
再输入 des 时就会把 description 提示出来。为什么上面的类型提示会失效?