From 7f1742633ffa5112c759da7a6436d1d95f81ec5d Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 19 Dec 2024 12:35:56 -0500 Subject: [PATCH] type-fix for LazyJsonString call interface (#1476) --- .changeset/khaki-clouds-tease.md | 5 +++++ packages/smithy-client/src/lazy-json.ts | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/khaki-clouds-tease.md diff --git a/.changeset/khaki-clouds-tease.md b/.changeset/khaki-clouds-tease.md new file mode 100644 index 00000000000..f94e4d2c9a2 --- /dev/null +++ b/.changeset/khaki-clouds-tease.md @@ -0,0 +1,5 @@ +--- +"@smithy/smithy-client": patch +--- + +fix new operator typing for LazyJsonString diff --git a/packages/smithy-client/src/lazy-json.ts b/packages/smithy-client/src/lazy-json.ts index 02aaf8f23bd..105b4c119ad 100644 --- a/packages/smithy-client/src/lazy-json.ts +++ b/packages/smithy-client/src/lazy-json.ts @@ -17,8 +17,6 @@ export type AutomaticJsonStringConversion = Parameters[0] * */ export interface LazyJsonString extends String { - new (s: string): typeof LazyJsonString; - /** * @returns the JSON parsing of the string value. */ @@ -40,7 +38,7 @@ export interface LazyJsonString extends String { * This current implementation may look strange, but is necessary to preserve the interface and * behavior of extending the String class. */ -export function LazyJsonString(val: string): void { +export const LazyJsonString = function LazyJsonString(val: string): void { const str = Object.assign(new String(val), { deserializeJSON() { return JSON.parse(String(val)); @@ -56,7 +54,15 @@ export function LazyJsonString(val: string): void { }); return str as never; -} +} as any as { + new (s: string): LazyJsonString; + (s: string): LazyJsonString; + from(s: any): LazyJsonString; + /** + * @deprecated use #from. + */ + fromObject(s: any): LazyJsonString; +}; LazyJsonString.from = (object: any): LazyJsonString => { if (object && typeof object === "object" && (object instanceof LazyJsonString || "deserializeJSON" in object)) { @@ -68,6 +74,6 @@ LazyJsonString.from = (object: any): LazyJsonString => { }; /** - * @deprecated use from. + * @deprecated use #from. */ LazyJsonString.fromObject = LazyJsonString.from;