Type GetStaticProps needs some tinker
See original GitHub issueDescribe the feature you’d like to request
Summary
next.GetStaticProps
stop extends return type to Record<string,any>
Detailed
Say I have a getStaticProps
like this.
const getStaticProps = async () => {
const typedProps = {
str: "stringType",
num: 123,
}
return {
props: typedProps,
};
};
Typescript knows the type of typedProps
const typedProps: {
str: string;
num: number;
}
And the InferGetStaticPropsType<typeof getStaticProps>
in the same page works correctly.
However, after adding the type GetStaticProps
to the getStaticProps
. the const SomePage: NextPage<InferGetStaticPropsType<typeof getStaticProps>>
starts to accept {[key: string]: any}
as its argument and all type information of the props is lost (converted to any
).
Describe the solution you’d like
I want GetStaticProps<P,Q,D>
stop to have default value of P = { [key: string]: any }
from https://github.com/vercel/next.js/blob/ccd3df2f812c98874273de7b237baa9c2ad8f309/packages/next/types/index.d.ts#L118-L124
But to me this is limited by TS engine, so I don’t know how to fix it. (otherwise I’d make a PR)
Describe alternatives you’ve considered
Not use GetStaticProps. Deprecate this type
Related issues
Issue Analytics
- State:
- Created a year ago
- Comments:15
Top GitHub Comments
Yeah that would be a better approach but also will not make people happy when their builds suddenly start to fail and the only solution to this is declaring props interfaces on potentially 100s of page components.
What I ment is that you do
So you declare Props once, but you use it twice.