Skip to content

How can i change type of context.req in GetServerSideProps? #36271

Answered by icyJoseph
Sh031224 asked this question in Help
Discussion options

You must be logged in to vote

Mmm, because the types GetServerSideProps and GetServerSidePropsContext are type aliases, they can't really be augmented, which is a natural property of interfaces. I think, if you create a global.d.ts file and add this:

import type {GetServerSidePropsContext as OriginalGetServerSidePropsContext} from 'next/types';

declare module 'next' {
    export type GetServerSidePropsContext<
        Q extends ParsedUrlQuery = ParsedUrlQuery,
        D extends PreviewData = PreviewData
    > = OriginalGetServerSidePropsContext<Q, D> & {
        req: {
            foo: string;
        };
    };

    export type GetServerSideProps<
        P extends {[key: string]: any} = {[key: string]: any},
        Q 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Sh031224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants