-
-
Notifications
You must be signed in to change notification settings - Fork 456
Closed
Description
Example
const queryStringParams = queryString.parse(search);
const sourceInjectedQueryString = queryString.stringifyUrl({
url: source,
query: queryStringParams,
});
Error
[tsserver 2322] [E] Type 'ParsedQuery<string>' is not assignable to type 'Record<string, string | null | undefined>'.
Index signatures are incompatible.
Type 'string | string[] | null' is not assignable to type 'string | null | undefined'.
Type 'string[]' is not assignable to type 'string'.
This is a regression introduced by b15f945
ParsedQuery type has array
export interface ParsedQuery<T = string> {
[key: string]: T | T[] | null;
}
UrlObject type does not support an array
export interface UrlObject {
readonly url: string;
/**
Qverrides queries in the `url` property.
*/
readonly query: Record<string, string | undefined | null>;
/**
Overrides the fragment identifier in the `url` property.
*/
readonly fragmentIdentifier?: string;
}
Note
Additionally it should support number
and boolean
since these are also stringifiable.
The type of object
argument in stringify
should also match the type of query
in stringifyUrl
as they both stringify a record.
Proposed Fix
export type Stringifiable = string | boolean | number;
export type StringifiableRecord = Record<
string,
Stringifiable | Stringifiable[] | null | undefined
>;
export interface UrlObject {
readonly url: string;
/**
Qverrides queries in the `url` property.
*/
readonly query: StringifiableRecord;
/**
Overrides the fragment identifier in the `url` property.
*/
readonly fragmentIdentifier?: string;
}
export function stringify(
object: StringifiableRecord,
options?: StringifyOptions
): string;
dlavrenuek
Metadata
Metadata
Assignees
Labels
No labels