fix: resolve TypeScript build errors in type declarations - #1326
fix: resolve TypeScript build errors in type declarations#1326alexs-mparticle wants to merge 6 commits into
Conversation
PR SummaryLow Risk Overview Public/runtime model updates include Internal wiring uses Tests that build consent rule payloads now 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
0109bad to
8ad352f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
- 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
There was a problem hiding this comment.
Remove Environment, like the bot says, not that you're not using it
There was a problem hiding this comment.
Although is there a reason to not use it?
| : 'production', | ||
| request_id: mpInstance._Helpers.generateUniqueId(), | ||
| request_timestamp_ms: new Date().getTime(), | ||
| request_timestamp_unixtime_ms: new Date().getTime(), |
| 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; |
There was a problem hiding this comment.
Shouldn't we not be using any if possible? why the reason for this change?
| window.mParticle && window.mParticle.config | ||
| ? window.mParticle.config | ||
| : {}; | ||
| const winMp = window.mParticle as any; |
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.
| */ | ||
| this.init = function(apiKey, config, instanceName) { | ||
| if (!config && (window.mParticle && window.mParticle.config)) { | ||
| const winMp = window.mParticle as any; |
| window.mParticle && window.mParticle.isIOS | ||
| ? window.mParticle.isIOS | ||
| : false; | ||
| const winMp = window.mParticle as any; |
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.
|



Summary
generateHashinterface return type (string→number) to match the implementation inutils.tsrequest_timestamp_ms→request_timestamp_unixtime_msinidentity.jsto satisfyIIdentityAPIRequestDataconvertProductActionToEventType/convertPromotionActionToEventTypereturn types:typeof CommerceEventType(namespace object) →valueof<typeof CommerceEventType>(a member value)createIdentityChangesreturn type inIIdentityRequest: single object →IIdentityAPIIdentityChangeData[](it actually returns an array)persistence.getLocalStorage,helpers.sanitizeAttributes, andidentity.mParticleUser/mParticleUserCartto unblock TS9005 declaration emitwindow.mParticle as anywhen accessing internal pre-init properties (config,isIOS,Store,_BatchValidator) not on the public@types/mparticle__web-sdktypeIConsentRulesValues.consentPurposetostring | number— tests usegenerateHash()(returnsnumber); JS auto-coerces numbers to strings as object keys so both work at runtimeTest Plan
npm run build— clean, zero errorsnpm run build:types— clean, zero TypeScript errorsnpm run test:jest— 540 tests passing across 23 suites