Skip to content

Commit 9fa2c42

Browse files
committed
Update type
1 parent 6e49927 commit 9fa2c42

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

packages/next/next-server/server/render.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ export async function renderToHTML(
763763
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
764764
}
765765

766-
if (data.unstable_notFound) {
766+
if ('unstable_notFound' in data) {
767767
if (pathname === '/404') {
768768
throw new Error(
769769
`The /404 page can not return unstable_notFound in "getStaticProps", please remove it to continue!`
@@ -775,13 +775,13 @@ export async function renderToHTML(
775775
}
776776

777777
if (
778-
data.unstable_redirect &&
778+
'unstable_redirect' in data &&
779779
typeof data.unstable_redirect === 'object'
780780
) {
781781
checkRedirectValues(data.unstable_redirect, req)
782782

783783
if (isDataReq) {
784-
data.props = {
784+
;(data as any).props = {
785785
__N_REDIRECT: data.unstable_redirect.destination,
786786
}
787787
} else {
@@ -792,15 +792,19 @@ export async function renderToHTML(
792792

793793
if (
794794
(dev || isBuildTimeSSG) &&
795-
!isSerializableProps(pathname, 'getServerSideProps', data.props)
795+
!isSerializableProps(
796+
pathname,
797+
'getServerSideProps',
798+
(data as any).props
799+
)
796800
) {
797801
// this fn should throw an error instead of ever returning `false`
798802
throw new Error(
799803
'invariant: getServerSideProps did not return valid props. Please report this.'
800804
)
801805
}
802806

803-
props.pageProps = Object.assign({}, props.pageProps, data.props)
807+
props.pageProps = Object.assign({}, props.pageProps, (data as any).props)
804808
;(renderOpts as any).pageData = props
805809
}
806810
} catch (dataFetchError) {

packages/next/types/index.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,16 @@ export type GetServerSidePropsContext<
132132
locales?: string[]
133133
}
134134

135-
export type GetServerSidePropsResult<P> = {
136-
props?: P
137-
unstable_redirect?: Redirect
138-
unstable_notFound?: true
139-
}
135+
export type GetServerSidePropsResult<P> =
136+
| {
137+
props: P
138+
}
139+
| {
140+
unstable_redirect: Redirect
141+
}
142+
| {
143+
unstable_notFound: true
144+
}
140145

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

0 commit comments

Comments
 (0)