Do we have Type system functionality inside an ActionRuntime function

I’ve a function that is running inside a nodejs ActionRuntime

  @nodejs(typeSystem=true, env='runtime')
  func: function(arg: ArgType): string

Then I’m trying this:

function func(arg) {
  var json = arg.toJSON();
}

But then I got this error

"Error executing command: node index.js
/private/var/folders/c1/lbt_3m017h73tb49yy7gyb2h0000gp/T/Lighthouse-generateReportHtml-997173700830831223/index.js:78
  var json = arg.toJSON();
                             ^

TypeError: arg.toJSON is not a function
    at func (/private/var/folders/c1/lbt_3m017h73tb49yy7gyb2h0000gp/T/TheType-func-997173700830831223/index.js:78:63)
    at /private/var/folders/c1/lbt_3m017h73tb49yy7gyb2h0000gp/T/TheType-func-997173700830831223/index.js:123:16
    at Socket.<anonymous> (/private/var/folders/c1/lbt_3m017h73tb49yy7gyb2h0000gp/T/TheType-func-997173700830831223/index.js:17:7)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
"

Looks like type.toJSON is a method defined within the global C3 util script that is loaded in console and not part of the type system - type.toJson is the method which is defined on the Obj type.

I haven’t used the @nodejs annotation and definitely haven’t used the typeSystem argument but I don’t think the global C3 object is made available on server side methods regardless of runtime. I would try using arg.toJson() and see if you have any success with that :slight_smile:

2 Likes