Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: import next types from 'next' #56

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 27 additions & 38 deletions src/types/next.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
import { IncomingMessage, ServerResponse } from 'http';
import type {
GetServerSideProps,
GetServerSidePropsContext,
GetServerSidePropsResult,
Redirect,
} from 'next';

import { ParsedUrlQuery } from './querystring';
export type RedirectStatusCode = Extract<
Redirect,
{ statusCode: number }
>['statusCode'];

export type RedirectStatusCode = 301 | 302 | 303 | 307 | 308;

export type Redirect =
| {
statusCode: RedirectStatusCode;
destination: string;
basePath?: false;
}
| {
permanent: boolean;
destination: string;
basePath?: false;
};

export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery,
> = {
req: IncomingMessage & {
cookies: Record<string, string>;
};
res: ServerResponse;
params?: Q;
query: ParsedUrlQuery;
export type {
GetServerSideProps,
GetServerSidePropsContext,
GetServerSidePropsResult,
Redirect,
};

export type PropResult<P extends Record<string, unknown>> = { props: P };
export type NotFoundResult = { notFound: true };
export type RedirectResult = { redirect: Redirect };
export type PropResult<P> = Extract<
GetServerSidePropsResult<P>,
{ props: any }
>;

export type GetServerSidePropsResult<P extends Record<string, unknown>> =
| PropResult<P>
| RedirectResult
| NotFoundResult;
export type NotFoundResult = Extract<
GetServerSidePropsResult<never>,
{ notFound: any }
>;

export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
> = (
context: GetServerSidePropsContext<Q>,
) => Promise<GetServerSidePropsResult<P>>;
export type RedirectResult = Extract<
GetServerSidePropsResult<never>,
{ redirect: any }
>;