Skip to content

fix: resolve TypeScript build errors in type declarations - #1326

Open
alexs-mparticle wants to merge 6 commits into
developmentfrom
fix/build-errors
Open

fix: resolve TypeScript build errors in type declarations#1326
alexs-mparticle wants to merge 6 commits into
developmentfrom
fix/build-errors

Conversation

@alexs-mparticle

Copy link
Copy Markdown
Collaborator

Summary

  • Fix generateHash interface return type (stringnumber) to match the implementation in utils.ts
  • Rename request_timestamp_msrequest_timestamp_unixtime_ms in identity.js to satisfy IIdentityAPIRequestData
  • Fix convertProductActionToEventType/convertPromotionActionToEventType return types: typeof CommerceEventType (namespace object) → valueof<typeof CommerceEventType> (a member value)
  • Fix createIdentityChanges return type in IIdentityRequest: single object → IIdentityAPIIdentityChangeData[] (it actually returns an array)
  • Add JSDoc return types to persistence.getLocalStorage, helpers.sanitizeAttributes, and identity.mParticleUser/mParticleUserCart to unblock TS9005 declaration emit
  • Cast window.mParticle as any when accessing internal pre-init properties (config, isIOS, Store, _BatchValidator) not on the public @types/mparticle__web-sdk type
  • Widen IConsentRulesValues.consentPurpose to string | number — tests use generateHash() (returns number); JS auto-coerces numbers to strings as object keys so both work at runtime

Test Plan

  • npm run build — clean, zero errors
  • npm run build:types — clean, zero TypeScript errors
  • npm run test:jest — 540 tests passing across 23 suites

@alexs-mparticle
alexs-mparticle requested a review from a team as a code owner August 18, 2026 15:21
@cursor

cursor Bot commented Aug 18, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are compile-time typing and test fixtures; runtime identity payloads and hashing behavior are unchanged aside from explicit string coercion in tests.

Overview
Aligns TypeScript interfaces with runtime behavior so build:types and declaration emit succeed without changing SDK logic.

Public/runtime model updates include generateHash returning number (matching utils.ts), commerce helper return types using valueof<typeof …> instead of typeof on enum-like objects, and identity API shapes (request_timestamp_ms, environment as string, identity_type as string, createIdentityChanges as an array with a fixed parameter name).

Internal wiring uses as unknown as casts when assigning concrete classes (Persistence, Helpers, Identity) to their interface types on the instance. window.mParticle is accessed via IMParticleInstanceManager instead of untyped property access for pre-init fields (config, isIOS, Store, _BatchValidator).

Tests that build consent rule payloads now String(mParticle.generateHash(...)) so consent purpose keys stay strings after the hash type correction.

Reviewed by Cursor Bugbot for commit f7cfc4f. Bugbot is set up for automated code reviews on this repo. Configure here.

- Fix generateHash interface return type (string → number) to match implementation
- Rename request_timestamp_ms → request_timestamp_unixtime_ms in identity.js to match IIdentityAPIRequestData
- Fix convertProductActionToEventType/convertPromotionActionToEventType return types (typeof Enum → valueof<typeof Enum>)
- Fix createIdentityChanges return type (single object → array) in IIdentityRequest
- Add JSDoc return types to persistence.getLocalStorage, helpers.sanitizeAttributes, identity.mParticleUser/mParticleUserCart to unblock declaration emit
- Cast window.mParticle to any when accessing internal pre-init properties (config, isIOS, Store, _BatchValidator) not in public type
- Widen IConsentRulesValues.consentPurpose to string | number to reflect JS key coercion behaviour

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8ad352f. Configure here.

Comment thread src/identity.js Outdated
- Revert IConsentRulesValues.consentPurpose to string; the number widening
  was unnecessary since hashConsentPurposeConditionalForwarding always
  returns .toString()
- Fix tests-cookie-syncing to wrap generateHash() in String() to match
@alexs-mparticle
alexs-mparticle changed the base branch from master to development August 18, 2026 18:41
Comment thread src/identity.interfaces.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Environment, like the bot says, not that you're not using it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although is there a reason to not use it?

Comment thread src/identity.js Outdated
: 'production',
request_id: mpInstance._Helpers.generateUniqueId(),
request_timestamp_ms: new Date().getTime(),
request_timestamp_unixtime_ms: new Date().getTime(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread src/mp-instance.ts Outdated
if (window.mParticle && window.mParticle.config) {
if (window.mParticle.config.hasOwnProperty('rq')) {
this._preInit.readyQueue = window.mParticle.config.rq;
const winMp = window.mParticle as any;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we not be using any if possible? why the reason for this change?

Comment thread src/mparticle-instance-manager.ts Outdated
window.mParticle && window.mParticle.config
? window.mParticle.config
: {};
const winMp = window.mParticle as any;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

The runtime field name request_timestamp_ms is correct per the IDSync
API contract. The interface had the wrong name (request_timestamp_unixtime_ms);
fix the interface and tests to match, not the other way around.

Also remove unused Environment import from identity.interfaces.ts.
Comment thread src/mparticle-instance-manager.ts Outdated
*/
this.init = function(apiKey, config, instanceName) {
if (!config && (window.mParticle && window.mParticle.config)) {
const winMp = window.mParticle as any;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tritto

Comment thread src/store.ts Outdated
window.mParticle && window.mParticle.isIOS
? window.mParticle.isIOS
: false;
const winMp = window.mParticle as any;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4itto

The public @types/mparticle__web-sdk type does not include internal
properties (config, isIOS, Store, _BatchValidator). IMParticleInstanceManager
already declares all of them, so cast to that instead of any.
The tsc declaration emit step uses || true so these errors are non-fatal.
No annotations needed in JS files.
TypeScript cannot verify that JS module implementations satisfy TS
interfaces. Cast _Persistence, _Helpers, and _Identity at their
assignment sites so declaration emit does not fail on type mismatches
caused by untyped JS return inference.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
52.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants