Skip to content

Commit 2b32b65

Browse files
committed
Improve type signature for return value to be based on first arg
Improves the type signature of the stringify function to take into account the main argument that we are serializing. If it is a primitive scalar, array, or object, and there is no second argument then the return value will always be a string. As this is the common case for user applications, this improves the user experience as we do not have to check the result to ensure the value is defined. For most use cases where the callsite has a primitive, array, or object and is using the default serilaization, the return value will be known to be a string
1 parent 30eaaa1 commit 2b32b65

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ declare namespace stableStringify {
1717
};
1818
}
1919

20+
declare function stableStringify(
21+
obj: string | number | boolean | Record<keyof any, unknown> | unknown[] | null
22+
): string;
23+
declare function stableStringify(
24+
obj: undefined
25+
): undefined;
2026
declare function stableStringify(
2127
obj: unknown,
2228
options?: (stableStringify.Comparator & stableStringify.StableStringifyOptions) | stableStringify.StableStringifyOptions,

0 commit comments

Comments
 (0)