@commercelayer/app-elements 1.14.5 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,12 +33,38 @@ export declare const createTypedRoute: <Parameters_1 extends Record<string, any>
33
33
  * name?: string | undefined;
34
34
  * }
35
35
  * ```
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const route = createTypedRoute<{ type: 'A' | 42; enabled?: boolean }>()(
40
+ * '/orders/:type/:enabled?/'
41
+ * )
42
+ *
43
+ * type Params = GetParams<typeof route>
44
+ *
45
+ * // equivalent to
46
+ *
47
+ * type Params = {
48
+ * type: 'A' | '42';
49
+ * enabled?: "false" | "true" | undefined;
50
+ * }
51
+ * ```
36
52
  */
37
53
  export type GetParams<R extends {
38
54
  makePath: (...arg: any[]) => string;
39
55
  }> = {
40
- [K in keyof Parameters<R['makePath']>[0]]: string;
56
+ [K in keyof Parameters<R['makePath']>[0]]: Exclude<ToLiteral<Parameters<R['makePath']>[0][K]>, 'undefined' | 'null'>;
41
57
  };
58
+ /**
59
+ * Cast a valid `string | number | bigint | boolean | null | undefined` to literal.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * type N = ToLiteral<42> //= '42'
64
+ * type B = ToLiteral<boolean> //= 'false' | 'true'
65
+ * ```
66
+ */
67
+ type ToLiteral<V extends string | number | bigint | boolean | null | undefined> = `${V}`;
42
68
  interface Route<Path extends `/${string}/` | `/`, Parameters extends Record<string, unknown> = ExtractParameters<Path>> {
43
69
  path: Path extends `/${infer P}/` ? `/${P}` : '/';
44
70
  makePath: (parameters: Parameters, searchParams?: string | URLSearchParams) => string;