Skip to content

Commit 73a35c1

Browse files
committed
ref: fix integration class type
1 parent 9d98364 commit 73a35c1

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

packages/core/src/integration.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,28 @@ function findIndex<T>(arr: T[], callback: (item: T) => boolean): number {
175175
export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
176176
name: string,
177177
fn: Fn,
178-
): IntegrationClass<
179-
Integration &
178+
): {
179+
id: string;
180+
new (...args: Parameters<Fn>): Integration &
180181
ReturnType<Fn> & {
181182
setupOnce: (addGlobalEventProcessor?: (callback: EventProcessor) => void, getCurrentHub?: () => Hub) => void;
182-
}
183-
> {
183+
};
184+
} {
184185
return Object.assign(
185186
// eslint-disable-next-line @typescript-eslint/no-explicit-any
186-
function ConvertedIntegration(...rest: any[]) {
187+
function ConvertedIntegration(...rest: Parameters<Fn>) {
187188
return {
188189
// eslint-disable-next-line @typescript-eslint/no-empty-function
189190
setupOnce: () => {},
190191
...fn(...rest),
191192
};
192193
},
193194
{ id: name },
194-
) as unknown as IntegrationClass<
195-
Integration &
195+
) as unknown as {
196+
id: string;
197+
new (...args: Parameters<Fn>): Integration &
196198
ReturnType<Fn> & {
197199
setupOnce: (addGlobalEventProcessor?: (callback: EventProcessor) => void, getCurrentHub?: () => Hub) => void;
198-
}
199-
>;
200+
};
201+
};
200202
}

packages/core/test/lib/integration.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,23 @@ describe('convertIntegrationFnToClass', () => {
670670
});
671671
});
672672

673+
it('works with options', () => {
674+
const integrationFn = (_options: { num: number }) => ({ name: 'testName' });
675+
676+
const IntegrationClass = convertIntegrationFnToClass('testName', integrationFn);
677+
678+
expect(IntegrationClass.id).toBe('testName');
679+
680+
// @ts-expect-error This should fail TS without options
681+
new IntegrationClass();
682+
683+
const integration = new IntegrationClass({ num: 3 });
684+
expect(integration).toEqual({
685+
name: 'testName',
686+
setupOnce: expect.any(Function),
687+
});
688+
});
689+
673690
it('works with integration hooks', () => {
674691
const setup = jest.fn();
675692
const setupOnce = jest.fn();

0 commit comments

Comments
 (0)