Skip to content

QueryParams ​

自 1.4.0 起

解析查询字符串为对象。

签名 ​

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

参数 ​

参数描述
S以 ? 开头的查询字符串

描述 ​

从 URL 查询字符串中提取键值对。

示例 ​

基本用法 ​

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

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

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

相关 ​

基于 MIT 许可发布