types-kit.urlquerytoobject.md

September 4, 2023 ยท View on GitHub

Home > types-kit > UrlQueryToObject

UrlQueryToObject type

Parser the querystring of a url into an object type

Signature:

export type UrlQueryToObject<T extends string> =
  T extends `${string}?${infer QueryString}`
    ? InternalUrlQueryToObject<QueryString>
    : InternalUrlQueryToObject<T>

References: InternalUrlQueryToObject

Example

// Expect: { a: ['1', '3'], b: '2', c: undefined }
type Foo = UrlQueryToObject<'/foo/bar?a=1&b=2&a=3&c'>