Skip to content

Commit

Permalink
better types
Browse files Browse the repository at this point in the history
  • Loading branch information
billyvg committed Feb 21, 2024
1 parent 0b69cfc commit fe68a8a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/feedback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"@sentry/types": "7.100.0",
"@sentry/utils": "7.100.0"
},
"devDependencies": {
"@sentry/replay": "7.100.0"
},
"scripts": {
"build": "run-p build:transpile build:types build:bundle",
"build:transpile": "rollup -c rollup.npm.config.mjs",
Expand Down
5 changes: 2 additions & 3 deletions packages/feedback/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type replayIntegration } from '@sentry/replay';
import type { BaseTransportOptions, Client, ClientOptions, Integration, IntegrationFn } from '@sentry/types';
import { isBrowser, logger } from '@sentry/utils';

Expand Down Expand Up @@ -197,15 +198,13 @@ export class Feedback implements Integration {
return;
}

const replay = client.getIntegrationByName!('Replay');
const replay = client.getIntegrationByName<ReturnType<typeof replayIntegration>>('Replay');

if (!replay) {
return;
}

try {
// @ts-expect-error Not sure how best to type this w/o
// making @sentry/replay a dep
replay.startBuffering();
} catch (err) {
DEBUG_BUILD && logger.error(err);
Expand Down
29 changes: 14 additions & 15 deletions packages/feedback/src/widget/createWidget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getClient, getCurrentScope } from '@sentry/core';
import { type replayIntegration } from '@sentry/replay';
import { logger } from '@sentry/utils';

import type { FeedbackFormData, FeedbackInternalOptions, FeedbackWidget } from '../types';
Expand Down Expand Up @@ -129,22 +130,20 @@ export function createWidget({
/**
* Internal handler when dialog is opened
*/
function handleOpenDialog({ includeReplay }: { includeReplay?: boolean } = {}) {
// Flush replay if it exists
if (includeReplay) {
const client = getClient();
const replay = client && client.getIntegrationByName!('Replay');
if (!replay) {
return;
}
try {
// @ts-expect-error Not sure how best to type this w/o
// making @sentry/replay a dep
void replay.flush();
} catch (err) {
DEBUG_BUILD && logger.error(err);
}
function handleOpenDialog({ includeReplay }: { includeReplay?: boolean } = {}): void {
if (!includeReplay) {
return;
}

// Flush replay if integration exists
const client = getClient();
const replay = client && client.getIntegrationByName<ReturnType<typeof replayIntegration>>('Replay');
if (!replay) {
return;
}
replay.flush().catch(err => {
DEBUG_BUILD && logger.error(err);
});
}

/**
Expand Down

0 comments on commit fe68a8a

Please sign in to comment.