ParamsOption
The params option a target needs.
The params option a target needs. A literal pattern with params (/posts/:id) needs exactly its
params, typed ({ id: string }), and an unknown name is an error; the params of an optional segment
are optional, and a pattern with only optional params leaves params optional. A concrete href, a
string, a runtime href and a union of targets keep the open record.
Import#
ts
import type { ParamsOption } from "@shadow-js/router";
Signature#
ts
type ParamsOption<P extends string> = [P] extends [never]
? OpenParamsOption
: string extends P
? OpenParamsOption
: [P] extends [RuntimeHref]
? OpenParamsOption
: IsUnion<P> extends true
? OpenParamsOption
: keyof ParamsOf<P> extends never
? OpenParamsOption
: Partial<ParamsOf<P>> extends ParamsOf<P>
? { readonly params?: ParamsOf<P> }
: { readonly params: ParamsOf<P> }
Examples#
ts
type PostParams = ParamsOption<"/posts/:id">; // { readonly params: { id: string } }