Skip to content

fix(feedback): Fix feedback type #11787

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

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/browser/src/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@sentry-internal/feedback';
import { lazyLoadIntegration } from './utils/lazyLoadIntegration';

// The full feedback widget, with everything pre-loaded
/** Add a widget to capture user feedback to your application. */
export const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration,
getModalIntegration: () => feedbackModalIntegration,
Expand Down
5 changes: 4 additions & 1 deletion packages/browser/src/feedbackAsync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { buildFeedbackIntegration } from '@sentry-internal/feedback';
import { lazyLoadIntegration } from './utils/lazyLoadIntegration';

// This is for users who want to have a lazy-loaded feedback widget
/**
* An integration to add user feedback to your application,
* while loading most of the code lazily only when it's needed.
*/
export const feedbackAsyncIntegration = buildFeedbackIntegration({
lazyLoadIntegration,
});
5 changes: 5 additions & 0 deletions packages/feedback/src/core/getFeedback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ describe('getFeedback', () => {
const actual = getFeedback();
expect(actual).toBeDefined();
expect(actual === configuredIntegration).toBe(true);

// has correct type
expect(typeof actual?.attachTo).toBe('function');
expect(typeof actual?.createWidget).toBe('function');
expect(typeof actual?.remove).toBe('function');
});
});
2 changes: 1 addition & 1 deletion packages/feedback/src/core/getFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type FeedbackIntegration = ReturnType<typeof buildFeedbackIntegration>;
*/
export function getFeedback(): ReturnType<FeedbackIntegration> | undefined {
const client = getClient();
return client && client.getIntegrationByName('Feedback');
return client && client.getIntegrationByName<ReturnType<FeedbackIntegration>>('Feedback');
}
9 changes: 8 additions & 1 deletion packages/feedback/src/core/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ interface BuilderOptions {
getModalIntegration?: null | (() => IntegrationFn);
getScreenshotIntegration?: null | (() => IntegrationFn);
}

export const buildFeedbackIntegration = ({
lazyLoadIntegration,
getModalIntegration,
getScreenshotIntegration,
}: BuilderOptions): IntegrationFn => {
}: BuilderOptions): IntegrationFn<
Integration & {
attachTo(el: Element | string, optionOverrides: OverrideFeedbackConfiguration): Unsubscribe;
createWidget(optionOverrides: OverrideFeedbackConfiguration): Promise<FeedbackDialog>;
remove(): void;
}
> => {
const feedbackIntegration = (({
// FeedbackGeneralConfiguration
id = 'sentry-feedback',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export interface Integration {
* An integration in function form.
* This is expected to return an integration.
*/
export type IntegrationFn = (...rest: any[]) => Integration;
export type IntegrationFn<IntegrationType = Integration> = (...rest: any[]) => IntegrationType;