diff --git a/index.d.ts b/index.d.ts index ab1e5d8c..78c0f187 100644 --- a/index.d.ts +++ b/index.d.ts @@ -339,11 +339,18 @@ export interface StringifyOptions { readonly skipEmptyString?: boolean; } +export type Stringifiable = string | boolean | number; + +export type StringifiableRecord = Record< + string, + Stringifiable | Stringifiable[] | null | undefined +>; + /** Stringify an object into a query string and sort the keys. */ export function stringify( - object: {[key: string]: any}, + object: StringifiableRecord, options?: StringifyOptions ): string; @@ -358,9 +365,9 @@ export interface UrlObject { readonly url: string; /** - Qverrides queries in the `url` property. + Overrides queries in the `url` property. */ - readonly query: Record; + readonly query: StringifiableRecord; /** Overrides the fragment identifier in the `url` property. diff --git a/index.test-d.ts b/index.test-d.ts index 72156b96..c83d2487 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -94,4 +94,19 @@ expectType( // Extract expectType(queryString.extract('http://foo.bar/?abc=def&hij=klm')); -expectType(queryString.stringifyUrl({url: 'https://sindresorhus.com', query: {foo: undefined}})); +expectType( + queryString.stringifyUrl({ + url: 'https://sindresorhus.com', + query: { + fooArray: [ + 'a', + 'b' + ], + fooNumber: 1, + fooBoolean: true, + fooNull: null, + fooUndefined: undefined, + fooString: 'hi' + }, + }) +);