Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v7 does not respect @sentry/react-native types #5206

Closed
3 tasks done
kopax-polyconseil opened this issue Jun 3, 2022 · 2 comments
Closed
3 tasks done

v7 does not respect @sentry/react-native types #5206

kopax-polyconseil opened this issue Jun 3, 2022 · 2 comments

Comments

@kopax-polyconseil
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which package are you using?

@sentry/react

SDK Version

latest

Framework Version

3.4.3

Link to Sentry event

No response

Steps to Reproduce

  1. create libs.ts
  2. add in libs.ts > export * from '@sentry/react-native' using v3.4.3
  3. add in libs.web.ts > export * from '@sentry/react' using v7.0.0
  4. create client.ts
  5. add this code:
import { CaptureContext, User, Event, SeverityLevel } from '@sentry/types'
import * as SentryModule from './libs'

type EventMonitoring = {
  captureException: (
    exception: unknown,
    captureContext?: CaptureContext | Record<string, unknown>
  ) => void
  captureEvent: (event: Event | Record<string, unknown>) => void
  captureMessage: (message: string, captureContext?: CaptureContext | SeverityLevel) => string
  configureScope: (callback: (scope: SentryModule.Scope) => void) => void
  init: ({ enabled }: { enabled: boolean }) => void
  setUser: (user: User | Record<string, unknown> | null) => void
}

export const eventMonitoring: EventMonitoring = {
  captureException: SentryModule.captureException,
  captureMessage: SentryModule.captureMessage,
  captureEvent: SentryModule.captureEvent,
  configureScope: SentryModule.configureScope,
  setUser: SentryModule.setUser,
  async init({ enabled } = { enabled: true }) {
    // if (!enabled) return
    const config = await getSentryConfig()
    SentryModule.init(config)
  },
}

Expected Result

Both interface from react-native and react have the same typing

Actual Result

Both interface from react-native and react have now different typing since v7

/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/src/libs/monitoring/services.ts
TypeScript error in /home/dka/workspace/github.com/pass-culture/pass-culture-app-native/src/libs/monitoring/services.ts(20,3):
Type '(exception: any, captureContext?: CaptureContext | undefined) => string' is not assignable to type '(exception: unknown, captureContext?: Record<string, unknown> | CaptureContext | undefined) => void'.
  Types of parameters 'captureContext' and 'captureContext' are incompatible.
    Type 'Record<string, unknown> | CaptureContext | undefined' is not assignable to type 'CaptureContext | undefined'.
      Type 'Scope' is not assignable to type 'CaptureContext | undefined'.
        Type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/types/types/scope").Scope' is not assignable to type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/react-native/node_modules/@sentry/types/dist/scope").Scope'.
          Types of property 'addEventProcessor' are incompatible.
            Type '(callback: import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/types/types/eventprocessor").EventProcessor) => import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/types/types/scope").Scope' is not assignable to type '(callback: import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/react-native/node_modules/@sentry/types/dist/eventprocessor").EventProcessor) => import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/react-native/node_modules/@sent...'.
              Types of parameters 'callback' and 'callback' are incompatible.
                Type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/react-native/node_modules/@sentry/types/dist/eventprocessor").EventProcessor' is not assignable to type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/types/types/eventprocessor").EventProcessor'.
                  Types of parameters 'event' and 'event' are incompatible.
                    Type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/types/types/event").Event' is not assignable to type 'import("/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@sentry/react-native/node_modules/@sentry/types/dist/event").Event'.
                      Types of property 'level' are incompatible.
                        Type 'SeverityLevel | Severity | undefined' is not assignable to type 'Severity | undefined'.
                          Type '"log"' is not assignable to type 'Severity | undefined'.  TS2322

    18 | 
    19 | export const eventMonitoring: EventMonitoring = {
  > 20 |   captureException: SentryModule.captureException,
       |   ^
    21 |   captureMessage: SentryModule.captureMessage,
    22 |   captureEvent: SentryModule.captureEvent,
    23 |   configureScope: SentryModule.configureScope,

Why did the react-native package did not get the same types upgrades ?

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Jun 3, 2022

Hey, thanks for writing in! Currently @sentry/react-native does not support the v7 SDK. Work is being done in getsentry/sentry-react-native#2250 to add support.

Please keep an eye on the React Native SDK releases to see when v7 support will come: https://github.com/getsentry/sentry-react-native/releases

In the mean time, please use the versions pinned to the React Native SDK package: https://github.com/getsentry/sentry-react-native/blob/acd746ae2b10c72e872df0fba329402675fe6d7e/package.json#L48 for @sentry/react

@kopax-polyconseil
Copy link
Author

kopax-polyconseil commented Jun 3, 2022

I have a typing problem and we only use a few methods from those sentry packages :

  • SentryModule.captureException
  • SentryModule.captureEvent
  • SentryModule.captureMessage
  • SentryModule.configureScope
  • SentryModule.setUser
  • SentryModule.init

So I hoped it would be oK.

Ignoring those types and it still seemed to be ok at least on Android.

Not sure if this resolve my initial bug I am working on (request 400 on sentry ping), I will have to open a new issue, you can view the bug here network tab.

This is the reason why I was trying to upgrade sentry sdk:

image
image

I will revert the upgrade of v7 then. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants