Skip to content

Sentry sdk adds "__wrapped"-properties to types, which prevents nestjs project from building #12682

@DanielMenke

Description

@DanielMenke

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nestjs

SDK Version

8.1.3.0

Framework Version

10.0.3

Link to Sentry event

No response

SDK Setup/Reproduction Example

import * as Sentry from '@sentry/node';

Sentry.init({
  dsn: 'X',
});
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const { httpAdapter } = app.get(HttpAdapterHost);
  Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));

 ...

  await app.listen(4000);
}

bootstrap();

Steps to Reproduce

  1. Use a custom Type which makes all properties of a type required:
export type Complete<T> = {
  [P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>>
    ? T[P]
    : T[P] | undefined;
};

in

export function UpdateContext<
  Model extends BaseModel,
  Dto extends Complete<Type<ContextAwareInput<GqlQueryContext>>>,
>(dto: Dto) {
  @ArgsType()
  class Context extends ContextAwareInput<GqlQueryContext> {
    @Field(() => ID)
    id: Model['id'];

    @Field(() => dto)
    dto: Dto;
  }

  return Context as Type<UpdateContext<Model, Dto>>;
}

and

async updateTreatment(
    @Update(UpdateInput) context: UpdateContext<Model, UpdateInput>
  ) {
    const entity = await this.service.findOneByContext(context);
    if (!entity) throw new NotFoundGqlError('Treatment not found');

    return this.service.updateByContext(entity, context);
  }
  1. Install @sentry/node

  2. run nest build

Expected Result

NestJs builds without Problems

Actual Result

The SDK expects the silently added __wrapped-property to be defined and Typescript throws the following Error:

TS2345: Argument of type 'typeof UpdateTreatmentInput' is not assignable to parameter of type 'Complete<Type<ContextAwareInput<GqlQueryContext>>>'.
  Property '__wrapped' is optional in type 'typeof UpdateTreatmentInput' but required in type 'Complete<Type<ContextAwareInput<GqlQueryContext>>>'.

Metadata

Metadata

Assignees

Labels

BugPackage: nestjsIssues related to the Sentry Nestjs SDK

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions