[njs] Types: fixed index types in modules.

Dmitry Volyntsev xeioex at nginx.com
Thu Oct 29 13:00:09 UTC 2020


details:   https://hg.nginx.org/njs/rev/3cc202e562e4
branches:  
changeset: 1553:3cc202e562e4
user:      Jakub Jirutka <jakub at jirutka.cz>
date:      Mon Oct 19 23:18:22 2020 +0200
description:
Types: fixed index types in modules.

Fixes the following type errors:
    Property ''xxx'' of type 'NjsByteString | undefined' is not
    assignable to string index type 'NjsStringLike'.ts(2411)

While string index signatures are a powerful way to describe the
"dictionary" pattern, they also enforce that all properties match
their return type.

diffstat:

 ts/ngx_http_js_module.d.ts   |  6 +++---
 ts/ngx_stream_js_module.d.ts |  2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 862ff6f2c684 -r 3cc202e562e4 ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.ts	Sat Oct 24 23:59:18 2020 +0200
+++ b/ts/ngx_http_js_module.d.ts	Mon Oct 19 23:18:22 2020 +0200
@@ -39,7 +39,7 @@ interface NginxHeadersIn {
     readonly 'Warning'?: NjsByteString;
     readonly 'X-Forwarded-For'?: NjsByteString;
 
-    readonly [prop: string]: NjsByteString;
+    readonly [prop: string]: NjsByteString | undefined;
 }
 
 interface NginxHeadersOut {
@@ -76,7 +76,7 @@ interface NginxHeadersOut {
 
     'Set-Cookie'?: NjsStringLike[];
 
-    [prop: string]: NjsStringLike | NjsStringLike[];
+    [prop: string]: NjsStringLike | NjsStringLike[] | undefined;
 }
 
 interface NginxVariables {
@@ -229,7 +229,7 @@ interface NginxVariables {
     readonly 'upstream_trailer_'?: NjsByteString;
     readonly 'uri'?: NjsByteString;
 
-    [prop: string]: NjsStringLike;
+    [prop: string]: NjsStringLike | undefined;
 }
 
 interface NginxSubrequestOptions {
diff -r 862ff6f2c684 -r 3cc202e562e4 ts/ngx_stream_js_module.d.ts
--- a/ts/ngx_stream_js_module.d.ts	Sat Oct 24 23:59:18 2020 +0200
+++ b/ts/ngx_stream_js_module.d.ts	Mon Oct 19 23:18:22 2020 +0200
@@ -66,7 +66,7 @@ interface NginxStreamVariables {
     readonly 'time_iso8601'?: NjsByteString;
     readonly 'time_local'?: NjsByteString;
 
-    [prop: string]: NjsByteString;
+    [prop: string]: NjsByteString | undefined;
 }
 
 interface NginxStreamCallbackFlags {


More information about the nginx-devel mailing list