[njs] Types: fixed signature of subrequest() with detached: true.

Dmitry Volyntsev xeioex at nginx.com
Mon Nov 2 12:43:40 UTC 2020


details:   https://hg.nginx.org/njs/rev/7ae9a0502fa1
branches:  
changeset: 1556:7ae9a0502fa1
user:      Jakub Jirutka <jakub at jirutka.cz>
date:      Sat Oct 31 22:38:22 2020 +0100
description:
Types: fixed signature of subrequest() with detached: true.

Order of method overloading declaration matters.

diffstat:

 test/ts/test.ts            |  10 +++++++---
 ts/ngx_http_js_module.d.ts |   4 ++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r fa3ffb3a159e -r 7ae9a0502fa1 test/ts/test.ts
--- a/test/ts/test.ts	Thu Oct 29 12:51:21 2020 +0000
+++ b/test/ts/test.ts	Sat Oct 31 22:38:22 2020 +0100
@@ -5,6 +5,7 @@ import crypto from 'crypto';
 function http_module(r: NginxHTTPRequest) {
     var bs: NjsByteString;
     var s: string;
+    var vod: void;
 
     // builtin string vs NjsByteString
 
@@ -57,9 +58,12 @@ function http_module(r: NginxHTTPRequest
 
     // r.subrequest
     r.subrequest('/p/sub1').then(reply => r.return(reply.status));
-    r.subrequest('/p/sub2', reply => r.return(reply.status));
-    r.subrequest('/p/sub3', {detached:true});
-    r.subrequest('/p/sub4', 'a=1&b=2').then(reply => r.return(reply.status,
+    r.subrequest('/p/sub2', {method:'POST'}).then(reply => r.return(reply.status));
+    vod = r.subrequest('/p/sub3', reply => r.return(reply.status));
+    vod = r.subrequest('/p/sub4', {method:'POST'}, reply => r.return(reply.status));
+    vod = r.subrequest('/p/sub5', {detached:true});
+    // Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply => r.return(reply.status));
+    r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
                                         JSON.stringify(JSON.parse(reply.responseBody ?? ''))));
 
 }
diff -r fa3ffb3a159e -r 7ae9a0502fa1 ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.ts	Thu Oct 29 12:51:21 2020 +0000
+++ b/ts/ngx_http_js_module.d.ts	Sat Oct 31 22:38:22 2020 +0100
@@ -346,11 +346,11 @@ interface NginxHTTPRequest {
      * @param options Subrequest options.
      * @param callback Completion callback.
      */
+    subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & { detached: true }): void;
     subrequest(uri: NjsStringLike, options?: NginxSubrequestOptions | string): Promise<NginxHTTPRequest>;
-    subrequest(uri: NjsStringLike, options: NginxSubrequestOptions | string,
+    subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & { detached?: false } | string,
                callback:(reply:NginxHTTPRequest) => void): void;
     subrequest(uri: NjsStringLike, callback:(reply:NginxHTTPRequest) => void): void;
-    subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & { detached: true }): void;
     /**
      * Current URI in request, normalized.
      */


More information about the nginx-devel mailing list