Skip to content
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

fix: type issues #1663

Merged
merged 5 commits into from
Mar 21, 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
4 changes: 2 additions & 2 deletions packages/analytics-js-common/src/types/Consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export type ConsentResolutionStrategy = 'and' | 'or';
export type Consents = string[];

export type ConsentManagementOptions = {
enabled: boolean;
provider: ConsentManagementProvider;
enabled?: boolean;
provider?: ConsentManagementProvider;
allowedConsentIds?: Consents;
deniedConsentIds?: Consents;
};
Expand Down
16 changes: 0 additions & 16 deletions packages/analytics-js-common/types/rudderanalytics.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/analytics-js/src/app/RudderAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
*/
triggerBufferedLoadEvent() {
const preloadedEventsArray = Array.isArray((globalThis as typeof window).rudderanalytics)
? ((globalThis as typeof window).rudderanalytics as PreloadedEventCall[])
? ((globalThis as typeof window).rudderanalytics as unknown as PreloadedEventCall[])
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
: ([] as PreloadedEventCall[]);

// The array will be mutated in the below method
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type PreloadedEventCall = Array<string | any>;

export type RudderAnalyticsPreloader = {
[index: string]: (...args: number[]) => any;
[index: string]: (...args: any[]) => any;
};
4 changes: 2 additions & 2 deletions packages/analytics-js/src/components/utilities/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ const getConsentManagerInfo = (
consentManagementOpts: ConsentManagementOptions,
logger?: ILogger,
) => {
let { provider }: { provider: ConsentManagementProvider | undefined } = consentManagementOpts;
const consentManagerPluginName = ConsentManagersToPluginNameMap[provider];
let { provider }: { provider?: ConsentManagementProvider } = consentManagementOpts;
const consentManagerPluginName = provider ? ConsentManagersToPluginNameMap[provider] : undefined;
if (provider && !consentManagerPluginName) {
logger?.error(
UNSUPPORTED_CONSENT_MANAGER_ERROR(CONFIG_MANAGER, provider, ConsentManagersToPluginNameMap),
Expand Down
9 changes: 3 additions & 6 deletions packages/analytics-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { RudderAnalytics } from './app/RudderAnalytics';
import type {
PreloadedEventCall,
RudderAnalyticsPreloader,
} from './components/preloadBuffer/types';
import type { RudderAnalyticsPreloader } from './components/preloadBuffer/types';
import type { IRudderStackGlobals } from './app/IRudderStackGlobals';

export {
Expand All @@ -26,13 +23,13 @@ export { type IdentifyTraits } from '@rudderstack/analytics-js-common/types/trai
export { RudderAnalytics } from './app/RudderAnalytics';
export { type IRudderStackGlobals } from './app/IRudderStackGlobals';
export {
type PreloadedEventCall,
type RudderAnalyticsPreloader,
type PreloadedEventCall,
} from './components/preloadBuffer/types';

declare global {
interface Window {
rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader;
rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
RudderStackGlobals: IRudderStackGlobals;
rudderAnalyticsMount: () => void;
rudderAnalyticsBuildType: 'legacy' | 'modern';
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-js/src/types/rudderanalytics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {

declare global {
interface Window {
rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader;
rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
RudderStackGlobals: IRudderStackGlobals;
rudderAnalyticsMount: () => void;
rudderAnalyticsBuildType: 'legacy' | 'modern';
Expand Down
4 changes: 2 additions & 2 deletions packages/loading-scripts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const sdkName = 'rsa.min.js';
const asyncScript = true;
window.rudderAnalyticsBuildType = 'legacy';

window.rudderanalytics = [];
(window.rudderanalytics as unknown as PreloadedEventCall[]) = [];
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
const methods: string[] = [
'setDefaultInstanceKey',
'load',
Expand All @@ -39,7 +39,7 @@ for (let i = 0; i < methods.length; i++) {
const method = methods[i] as string;
(window.rudderanalytics as unknown as RudderAnalyticsPreloader)[method] = (methodName =>
function () {
(window.rudderanalytics as PreloadedEventCall[]).push(
(window.rudderanalytics as unknown as PreloadedEventCall[]).push(
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
[methodName].concat(Array.prototype.slice.call(arguments) as PreloadedEventCall),
);
})(method);
Expand Down
2 changes: 1 addition & 1 deletion packages/loading-scripts/src/types/rudderanalytics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {

declare global {
interface Window {
rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader;
rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
RudderStackGlobals: IRudderStackGlobals;
rudderAnalyticsMount: () => void;
rudderAnalyticsBuildType: 'legacy' | 'modern';
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity-suite/src/types/rudderanalytics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {

declare global {
interface Window {
rudderanalytics: RudderAnalytics | PreloadedEventCall[] | RudderAnalyticsPreloader;
rudderanalytics: RudderAnalytics | RudderAnalyticsPreloader | undefined;
RudderStackGlobals: IRudderStackGlobals;
rudderAnalyticsMount: () => void;
rudderAnalyticsBuildType: 'legacy' | 'modern';
Expand Down