Giter Site home page Giter Site logo

Comments (4)

roderik avatar roderik commented on June 25, 2024

To make it worse, the re-exported withScope in @sentry/node is using this different Scope, so even an import line like import { Scope, addRequestDataToEvent, captureException, withScope } from '@sentry/node'; is incompatible

Nor does this work

import { Scope, withScope } from '@sentry/core';
import { addRequestDataToEvent, captureException } from '@sentry/node';

from sentry-javascript.

mydea avatar mydea commented on June 25, 2024

Hey,

could you share the actual code that is triggering this problem for you? e.g.

import {Scope} from '@sentry/node';

function myFunction(scope: Scope): void {
  xxx(scope);
}

It should be the case that you can pass the scope from @sentry/node everywhere - this is the actual scope class, while in all places that accept a scope we should be using the scope type. but it may be the case that we missed some place there 🤔

from sentry-javascript.

alumni avatar alumni commented on June 25, 2024

Sorry, I didn't write properly in the issue description, but it's exactly what @roderik is mentioning as well.

import { type Scope, withScope } from '@sentry/node';

withScope((scope: Scope) => {});
//         ^
// Argument of type
// 'import(".../node_modules/@sentry/types/types/scope").Scope'
// is not assignable to parameter of type
// 'import(".../node_modules/@sentry/core/types/scope").Scope'.

@sentry/node exports the Scope class from @sentry/core.
@sentry/node also exports withScope from @sentry/core. This withScope method has a callback argument of type Scope, an interface that comes from @sentry/types.

This was not the case in v7, where the Scope class was also used by the callback of withScope.

The class and the interface are not compatible with each other.

from sentry-javascript.

mydea avatar mydea commented on June 25, 2024

Ah, I see now.

Yeah, this is a bit annoying/tricky. What you can do for now is install @sentry/types and import all the types you use in your app from there:

import { withScope } from '@sentry/node';
import type { Scope } from '@sentry/types';

withScope(scope: Scope, () => {});

(that, or let the type be inferred, which should be correct as well).

I have opened a PR to fix this behavior in the next version: #12067
There, it should work again to do import type {Scope} from '@sentry/node' and get the expected behavior!

from sentry-javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.