1

I'm attempting to implement an iOS delegate in a NativeScript plugin and am getting an error:

Terminating app due to uncaught exception 'NativeScript encountered a fatal error: ReferenceError: Can't find variable: __metadata

My original code is:

@ObjCClass(SQRDCheckoutControllerDelegate) export class SquareReader extends NSObject implements SQRDCheckoutControllerDelegate { /* iOS delegate implementation here (source https://docs.connect.squareup.com/payments/readersdk/setup-ios) */ }

And that's getting transpiled in js down to:

SquareReader = __decorate([ ObjCClass(exports.SQRDCheckoutControllerDelegate), __metadata("design:paramtypes", []) ], SquareReader);

If I just remove the __metadata line, I get a different error:

Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: Protocol "undefined" is not a protocol object.

Any ideas? I've seen other examples like nativescript-image-swipe where the code is being transpiled w/o the __metadata method leading me to think something might be wrong with the transpilation

Frank
  • 399
  • 4
  • 16
  • Hi @Frank, Make sure that you have added `tns-platform-declarations` in your plugin - https://github.com/PeterStaev/nativescript-image-swipe/blob/master/package.json#L54 . More info how to set it up, can be found here - https://www.npmjs.com/package/tns-platform-declarations . – Nikolay Tsonev Oct 17 '18 at 05:57
  • @NikolayTsonev thanks for the tip. I do have tns-platform-declarations setup (I copied my plugin from the seed). Here's my package.json: [https://github.com/fhackenb/nativescript-square-reader/blob/master/src/package.json](https://github.com/fhackenb/nativescript-square-reader/blob/master/src/package.json) I also tried just cutting and pasting the relevant parts of Peter's code and it gave me the same error – Frank Oct 17 '18 at 13:41

1 Answers1

0

I solved this by cleaning up my typings. I just re-ran the command to generate typings: TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios and put them in my /src directory for my plugin. Once my typings were correct the project ran as expected and the Delegate worked

Frank
  • 399
  • 4
  • 16