From 5f2806a104027e8310770f2ca8e4c350064c2c5a Mon Sep 17 00:00:00 2001 From: "Artem S. Povalyukhin" Date: Sat, 27 Jun 2020 19:26:41 +0300 Subject: [PATCH] Fixed TypeScript description for NjsByteString type. NjsByteString was declared as it has no relation to string primitive type. This causes a problem when a variable of type NjsByteString is passed into built-in functions expecting string type. The issue was introduced in 8f3ef384f69e. --- src/ts/njs_core.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ts/njs_core.d.ts b/src/ts/njs_core.d.ts index a632d1fd..9abcee52 100644 --- a/src/ts/njs_core.d.ts +++ b/src/ts/njs_core.d.ts @@ -14,14 +14,14 @@ interface String { * Serializes a Unicode string with code points up to 255 * into a byte string, otherwise, null is returned. */ - toBytes(start?: number, end?: number): NjsByteString; + toBytes(start?: number, end?: number): NjsByteString | null; /** * Serializes a Unicode string to a byte string using UTF8 encoding. */ toUTF8(start?: number, end?: number): NjsByteString; } -interface NjsByteString extends String { +type NjsByteString = string & { /** * Returns a new Unicode string from a byte string where each byte is replaced * with a corresponding Unicode code point. @@ -31,12 +31,12 @@ interface NjsByteString extends String { * Converts a byte string containing a valid UTF8 string into a Unicode string, * otherwise null is returned. */ - fromUTF8(start?: number, end?: number): string; + fromUTF8(start?: number, end?: number): string | null; /** * Encodes a byte string to hex, base64, or base64url. */ - toString(encoding?: "hex" | "base64" | "base64url"): string; -} + toString(encoding: "hex" | "base64" | "base64url"): string; +}; type NjsStringLike = string | NjsByteString; -- 2.47.3