UNPKG

1.79 kBTypeScriptView Raw
1import { StaticPath, StaticPropsContext } from './scripts/build';
2import { ComponentProps, JSX, ComponentType } from "preact";
3declare type RestParam<S extends string> = S extends `...${infer A}` ? A : never;
4declare type StandardParam<S extends string> = S extends `...${infer A}` ? never : S;
5declare type ExtractParams<S extends string> = S extends `[${infer A}]` ? A : never;
6declare type TupleToUnion<T extends any[]> = T[number];
7declare type Split<S extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [
8 S
9];
10declare type NormalizePath<S extends string> = S extends `/${infer T}` ? T : S;
11declare type AllPathParams<S extends string, P extends string = ExtractParams<TupleToUnion<Split<NormalizePath<S>>>>> = {
12 [param in P]: string | string[];
13};
14declare type RestParams<S extends string, Base extends string = keyof AllPathParams<S>> = {
15 [a in RestParam<Base>]: string[];
16};
17declare type StandardParams<S extends string, Base extends string = keyof AllPathParams<S>> = {
18 [a in StandardParam<Base>]: string;
19};
20export declare type PathParams<S extends string> = RestParams<S> & StandardParams<S>;
21export declare function definePage<T extends ComponentType<any> | keyof JSX.IntrinsicElements, Path extends string, P extends PathParams<Path>>(Component: T, page?: {
22 path?: Path;
23 getStaticPaths?: () => Promise<{
24 paths: StaticPath<P>[];
25 }>;
26 getStaticProps?: (ctx: StaticPropsContext<P>) => Promise<{
27 props: ComponentProps<T>;
28 }>;
29}): {
30 path?: Path;
31 getStaticPaths?: () => Promise<{
32 paths: StaticPath<P>[];
33 }>;
34 getStaticProps?: (ctx: StaticPropsContext<P>) => Promise<{
35 props: ComponentProps<T>;
36 }>;
37 Component: T;
38};
39export {};