type-alias / @typed/router/Uri

ParseUri

Parses a URI string literal into component literal types, optionally against a base URI.

Package version
1.0.0-beta.13
Category
URI type inference
Since
1.0.0

Import

import type { ParseUri } from "@typed/router/Uri";

Signatures

export type ParseUri<Input extends string, BaseUri extends string = never> = Pipe<Input, ParseUriLambda, [
    BaseUri
] extends [
    never
] ? Identity : ApplyBaseUriLambda<ParseUri<BaseUri>>> extends infer R ? Uri<GetUriKey<R, "protocol">, GetUriKey<R, "username">, GetUriKey<R, "password">, GetUriKey<R, "hostname">, GetUriKey<R, "port">, GetUriKey<R, "pathname">, GetUriKey<R, "query">, GetUriKey<R, "hash">> : never;

Why

Route type utilities can reason about origin and path components without widening to string.

Ownership and lifetime

ParseUri evaluates the URI parser only for string-literal inputs; its component result is erased from emitted JavaScript.

Examples

import type { ParseUri } from "@typed/router/Uri"

type Account = ParseUri<"/account?tab=profile", "https://example.com/">

Source