Skip to content

Commit

Permalink
fix: redefine urllib export types (#5386)
Browse files Browse the repository at this point in the history
```bash
node_modules/.store/[email protected]/node_modules/egg/index.d.ts:63:3 - error TS2666: Exports and export assignments are not permitted in module augmentations.

63   export { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse };
     ~~~~~~

Found 1 error in node_modules/.store/[email protected]/node_modules/egg/index.d.ts:63
```
  • Loading branch information
fengmk2 authored Jan 19, 2025
1 parent a612e80 commit 02d9fdb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ site/dist
.umi-production
.vercel
package-lock.json
.tshy*
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
HttpClientResponse as HttpClientResponseOld,
} from 'urllib';
import {
RequestURL as HttpClientRequestURL,
RequestOptions as HttpClientRequestOptions,
HttpClientResponse,
RequestURL,
RequestOptions,
HttpClientResponse as HttpClientResponseNext,
} from 'urllib-next';
import {
EggCoreBase,
Expand Down Expand Up @@ -60,7 +60,9 @@ declare module 'egg' {
// return await app.httpclient.request(url, options);
// }
// ```
export { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse };
export type HttpClientRequestURL = RequestURL;
export type HttpClientRequestOptions = RequestOptions;
export type HttpClientResponse<T = any> = HttpClientResponseNext<T>;
// Compatible with both urllib@2 and urllib@3 RequestOptions to request
export interface EggHttpClient extends EventEmitter {
request<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/apps/app-ts/app/controller/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
EggLogger,
EggHttpClient,
EggContextHttpClient,
HttpClientRequestURL,
HttpClientRequestOptions as RequestOptionsNext,
} from 'egg';
import { RequestOptions as RequestOptionsNext } from 'urllib-next';
import { RequestOptions2, RequestOptions } from 'urllib';

// add user controller and service
Expand Down Expand Up @@ -59,8 +60,8 @@ export default class FooController extends Controller {
}
}

async requestWithHttpclientNext(request: RequestOptionsNext) {
let result = await this.app.curl('url', request);
async requestWithHttpclientNext(request: RequestOptionsNext, url?: HttpClientRequestURL) {
let result = await this.app.curl(url ?? 'url', request);
result = await this.ctx.curl('url', request);
result = await this.app.httpclient.curl('url', request);
result = await this.app.httpclient.request('url', request);
Expand Down

0 comments on commit 02d9fdb

Please sign in to comment.