From 02d9fdb7c127f9e8150bdb8f23977a2effeaf6ae Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 19 Jan 2025 20:12:05 +0800 Subject: [PATCH] fix: redefine urllib export types (#5386) ```bash node_modules/.store/egg@3.30.0/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/egg@3.30.0/node_modules/egg/index.d.ts:63 ``` --- .gitignore | 1 + index.d.ts | 10 ++++++---- test/fixtures/apps/app-ts/app/controller/foo.ts | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8fe303468d..cd6dbe2e05 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ site/dist .umi-production .vercel package-lock.json +.tshy* diff --git a/index.d.ts b/index.d.ts index 2b2868762c..760f505e7a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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, @@ -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 = HttpClientResponseNext; // Compatible with both urllib@2 and urllib@3 RequestOptions to request export interface EggHttpClient extends EventEmitter { request(url: HttpClientRequestURL): Promise | HttpClientResponse>; diff --git a/test/fixtures/apps/app-ts/app/controller/foo.ts b/test/fixtures/apps/app-ts/app/controller/foo.ts index 1ec36c7800..614477d961 100644 --- a/test/fixtures/apps/app-ts/app/controller/foo.ts +++ b/test/fixtures/apps/app-ts/app/controller/foo.ts @@ -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 @@ -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);