Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Class 'MonitoringError' incorrectly extends base class 'Error'

$
0
0

Im trying to extend the Error class with the following ( for monitoring with Sentry in React Native ) but get the following error.

Class 'MonitoringError' incorrectly extends base class 'Error'.      Types of property 'name' are incompatible.        Type 'string | boolean | CaptureContext | undefined' is not assignable to type 'string'.          Type 'undefined' is not assignable to type 'string'.

With the following code

import { CaptureContext } from '@sentry/types';import { ComponentType } from 'react';import { FallbackProps } from 'react-error-boundary';import { eventMonitoring } from './SentryCrashlyticsService';export class MonitoringError extends Error {  constructor(    public message: string,    public name?: string | CaptureContext | boolean,    public captureContext?: CaptureContext | boolean,  ) {    super(message);  }  public capture: () => void = () => {    let skipLogging = false as boolean | undefined;    let ctx = this.captureContext;    let name;    if (this.name && typeof this.name === 'string') {      name = this.name;    } else if (this.name && typeof this.name === 'boolean') {      skipLogging = name;    } else if (name) {      ctx = name as CaptureContext;    }    if (typeof this.captureContext === 'boolean'&& !skipLogging) {      skipLogging = true;    }    if (!skipLogging) {      eventMonitoring.captureException(this, ctx as CaptureContext);    }  };}

Whats the best way to extend, if possible.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>