Skip to content

QueryParams

Since 1.4.0

Parse query string into object.

Signature

typescript
type QueryParams<S extends string> = S extends `?${infer Rest}` ? ParseQueryPairs<Rest> : Record<string, never>

Parameters

ParameterDescription
SQuery string starting with ?

Description

Extracts key-value pairs from URL query string.

Examples

Basic Usage

typescript
import type { QueryParams } from 'uni-types'

type Params = QueryParams<'?a=1&b=2'>
// { a: '1'; b: '2' }

type Empty = QueryParams<'?'>
// {}

Released under the MIT License.