From 2b32b65e9f22834d6cfdb3df5fe749465b79bb16 Mon Sep 17 00:00:00 2001 From: Sehrope Sarkuni Date: Wed, 6 Aug 2025 13:45:58 -0400 Subject: [PATCH] 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 --- index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.d.ts b/index.d.ts index d42fb1d..5594ea1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,6 +17,12 @@ declare namespace stableStringify { }; } +declare function stableStringify( + obj: string | number | boolean | Record | unknown[] | null +): string; +declare function stableStringify( + obj: undefined +): undefined; declare function stableStringify( obj: unknown, options?: (stableStringify.Comparator & stableStringify.StableStringifyOptions) | stableStringify.StableStringifyOptions,