Skip to content

Instantly share code, notes, and snippets.

@garand
Created May 17, 2021 19:56
Show Gist options
  • Save garand/deee6a30b79f4e4bc99ad668a69d932e to your computer and use it in GitHub Desktop.
Save garand/deee6a30b79f4e4bc99ad668a69d932e to your computer and use it in GitHub Desktop.
Utility to convert object values to strings
/**
* Convert object of unknown value types to strings for use as request query params
*/
export function paramify<T>(
params?: T
): { [key in keyof T]: string } | undefined {
if (!params) return undefined;
return Object.fromEntries(
Object.entries(params).map((param) => [param[0], String(param[1])])
) as { [key in keyof T]: string };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment