Skip to content

Commit

Permalink
type-fix for LazyJsonString call interface (smithy-lang#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Dec 19, 2024
1 parent e27d42d commit 7f17426
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-clouds-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/smithy-client": patch
---

fix new operator typing for LazyJsonString
16 changes: 11 additions & 5 deletions packages/smithy-client/src/lazy-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export type AutomaticJsonStringConversion = Parameters<typeof JSON.stringify>[0]
*
*/
export interface LazyJsonString extends String {
new (s: string): typeof LazyJsonString;

/**
* @returns the JSON parsing of the string value.
*/
Expand All @@ -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));
Expand All @@ -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)) {
Expand All @@ -68,6 +74,6 @@ LazyJsonString.from = (object: any): LazyJsonString => {
};

/**
* @deprecated use from.
* @deprecated use #from.
*/
LazyJsonString.fromObject = LazyJsonString.from;

0 comments on commit 7f17426

Please sign in to comment.