Problem when porting app from Ionic 5 ⇨ 6 / Capacitor 2 ⇨ 3

Hi,

I try to port my app but I get an error during ionic build. Here is me code snippet

      if (Capacitor.getPlatform() == "ios")
      {
        this.storage.set ("iapID", p.transaction.original_transaction_id);
      }
      else
      {
        this.storage.set ("iapID", p.transaction.purchaseToken);
      }

Error Message

Error: src/app/iap.service.ts:91:54 - error TS2339: Property ‘original_transaction_id’ does not exist on type ‘PlayStoreReceipt | AppStoreReceipt’.
Property ‘original_transaction_id’ does not exist on type ‘PlayStoreReceipt’.

91 this.storage.set (“iapID”, p.transaction.original_transaction_id);
~~~~~~~~~~~~~~~~~~~~~~~

Error: src/app/iap.service.ts:95:54 - error TS2339: Property ‘purchaseToken’ does not exist on type ‘PlayStoreReceipt | AppStoreReceipt’.
Property ‘purchaseToken’ does not exist on type ‘AppStoreReceipt’.

95 this.storage.set (“iapID”, p.transaction.purchaseToken);

It seems, that the type of the property transaction has changed. Any ideas how to solve this issue?

Just out of curiosity- why is there a space between get/set and the opening parenthesis?

you must check if the plugin is compatible with capacitor 3

I found the solution myself. Just want to document it, if someone has a similar problem

The solution is to use the in operator

      if ("original_transaction_id" in p.transaction)
      {
        this.storage.set ("iapID", p.transaction.original_transaction_id);
      }
      else
      {
        this.storage.set ("iapID", p.transaction.purchaseToken);
      }