Skip to content

Commit 79818ff

Browse files
mydeaLms24
andauthored
fix(feedback): Fix feedback type (#11787)
Noticed this while bumping sentry itself - the types are wrong today, because we return it as `IntegrationFn` which is just a generic integration with no custom methods. --------- Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
1 parent 18ba344 commit 79818ff

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

packages/browser/src/feedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@sentry-internal/feedback';
66
import { lazyLoadIntegration } from './utils/lazyLoadIntegration';
77

8-
// The full feedback widget, with everything pre-loaded
8+
/** Add a widget to capture user feedback to your application. */
99
export const feedbackIntegration = buildFeedbackIntegration({
1010
lazyLoadIntegration,
1111
getModalIntegration: () => feedbackModalIntegration,

packages/browser/src/feedbackAsync.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { buildFeedbackIntegration } from '@sentry-internal/feedback';
22
import { lazyLoadIntegration } from './utils/lazyLoadIntegration';
33

4-
// This is for users who want to have a lazy-loaded feedback widget
4+
/**
5+
* An integration to add user feedback to your application,
6+
* while loading most of the code lazily only when it's needed.
7+
*/
58
export const feedbackAsyncIntegration = buildFeedbackIntegration({
69
lazyLoadIntegration,
710
});

packages/feedback/src/core/getFeedback.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ describe('getFeedback', () => {
3939
const actual = getFeedback();
4040
expect(actual).toBeDefined();
4141
expect(actual === configuredIntegration).toBe(true);
42+
43+
// has correct type
44+
expect(typeof actual?.attachTo).toBe('function');
45+
expect(typeof actual?.createWidget).toBe('function');
46+
expect(typeof actual?.remove).toBe('function');
4247
});
4348
});

packages/feedback/src/core/getFeedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ type FeedbackIntegration = ReturnType<typeof buildFeedbackIntegration>;
88
*/
99
export function getFeedback(): ReturnType<FeedbackIntegration> | undefined {
1010
const client = getClient();
11-
return client && client.getIntegrationByName('Feedback');
11+
return client && client.getIntegrationByName<ReturnType<FeedbackIntegration>>('Feedback');
1212
}

packages/feedback/src/core/integration.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ interface BuilderOptions {
4545
getModalIntegration?: null | (() => IntegrationFn);
4646
getScreenshotIntegration?: null | (() => IntegrationFn);
4747
}
48+
4849
export const buildFeedbackIntegration = ({
4950
lazyLoadIntegration,
5051
getModalIntegration,
5152
getScreenshotIntegration,
52-
}: BuilderOptions): IntegrationFn => {
53+
}: BuilderOptions): IntegrationFn<
54+
Integration & {
55+
attachTo(el: Element | string, optionOverrides: OverrideFeedbackConfiguration): Unsubscribe;
56+
createWidget(optionOverrides: OverrideFeedbackConfiguration): Promise<FeedbackDialog>;
57+
remove(): void;
58+
}
59+
> => {
5360
const feedbackIntegration = (({
5461
// FeedbackGeneralConfiguration
5562
id = 'sentry-feedback',

packages/types/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ export interface Integration {
5757
* An integration in function form.
5858
* This is expected to return an integration.
5959
*/
60-
export type IntegrationFn = (...rest: any[]) => Integration;
60+
export type IntegrationFn<IntegrationType = Integration> = (...rest: any[]) => IntegrationType;

0 commit comments

Comments
 (0)