AutoJs6-TypeScript-Declarations
AutoJs6-TypeScript-Declarations copied to clipboard
关于 http.get 在不指定 callback 时的类型提示问题
在使用 http.get 等 api 发送请求时,如果不填 callback 参数的话是同步执行,函数会 return 一个 response 对象。如果填了这个参数就不会 return 内容。但现在 http.get 在不填 callback 参数时返回类型的提示是 void | Http.WrappedResponse 而非 Http.WrappedResponse。
这样会导致
resp.body 被推断成为 any 类型,因此像 resp.body.string() 这样的代码就没有类型提示。
翻了下源码,发现 get 没有重载,多种传参方式共用一个函数定义。 https://github.com/SuperMonster003/AutoJs6-TypeScript-Declarations/blob/58af96029f62aaaa4ffdc925cf468a6e31188220/declarations/autojs6/aj6-int-http.d.ts#L72
如果能改成这种形式的话就更好了。
get(url: string): Http.WrappedResponse;
get(url: string, options: Http.RequestBuilderOptions): Http.WrappedResponse;
get(url: string, options: Http.RequestBuilderOptions, callback: Http.Callback): void;
如果没什么问题的话,我直接提个 PR 解决这个问题吧。
ok