Skip to content

Typing issue with the custom _error page in TypeScript #5448

Closed
@simontaisne

Description

@simontaisne

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.7.0

Framework Version

12.2.2

Link to Sentry event

No response

Steps to Reproduce

  1. Run the wizard command
npx @sentry/wizard -i nextjs
  1. Rename the generated_error.js custom page to _error.tsx
  2. Provide the ErrorProps type from next/error to the CustomErrorComponent
import NextErrorComponent from 'next/error';
import type { NextPage } from 'next';
import type { ErrorProps } from 'next/error';
import * as Sentry from '@sentry/nextjs';

const CustomErrorComponent: NextPage<ErrorProps> = ({ statusCode }) => {
  return <NextErrorComponent statusCode={statusCode} />;
};

CustomErrorComponent.getInitialProps = async (context) => {
  await Sentry.captureUnderscoreErrorException(context);
  // -------------------------------------------^^^^^

  return NextErrorComponent.getInitialProps(context);
};

export default CustomErrorComponent;

Expected Result

No typing issue with TypeScript.

Actual Result

Argument of type 'NextPageContext' is not assignable to parameter of type 'ContextOrProps'.
  Index signature for type 'string' is missing in type 'NextPageContext'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions