Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration.transform incorrectly typed #985

Closed
goibon opened this issue Jan 28, 2022 · 4 comments
Closed

Configuration.transform incorrectly typed #985

goibon opened this issue Jan 28, 2022 · 4 comments

Comments

@goibon
Copy link

goibon commented Jan 28, 2022

Reading up on how to use source maps when you serve your code on multiple domains I seem to have run into an issue where the transform function of the configuration object is not properly typed.

The code sample from the source map documentation (as of writing) looks like this:

var _rollbarConfig = {
  // ...
  transform: function(payload) {
    var trace = payload.body.trace;
    // Change 'yourdomainhere' to your domain.
    var locRegex = /^(https?):\/\/[a-zA-Z0-9._-]+\.yourdomainhere\.com(.*)/;
    if (trace && trace.frames) {
      for (var i = 0; i < trace.frames.length; i++) {
        var filename = trace.frames[i].filename;
        if (filename) {
          var m = filename.match(locRegex);
          // Be sure that the minified_url when uploading includes 'dynamichost'
          trace.frames[i].filename = m[1] + '://dynamichost' + m[2];          
        }
      }
    }
  }
}

According to that code sample it would sure seem that the first parameter of the transform function would not just be an object but looks more like:

transform: function (payload: { body: { trace?: { frames: {filename: string}[] } } } )

There is probably a plethora of other fields in the payload parameter (and it's underlying fields) that I don't know about yet.

Am I overlooking something or is there a disconnect between the typing of transform in this repo and the documentation example?

*Edit* I should probably mention that I am using rollbar version 2.24.0

@waltjones
Copy link
Contributor

The payload structure is documented here: https://explorer.docs.rollbar.com/#tag/Item

When you say incorrectly typed, are you referring to the Typescript declaration?

@goibon
Copy link
Author

goibon commented Mar 23, 2022

@waltjones Thank you for the link, that does clarify a bit how the payload structure is expected to look 👍

When you say incorrectly typed, are you referring to the Typescript declaration?

Yes exactly, that's why I linked to the index.d.ts file (although I realize now that I linked to master instead of the 2.24.0 so I'll update the link)
On line 92 of index.d.ts in v. 2.24.0 the transform function is typed as: transform?: (data: object) => void; this means that when I try to sample code snippet from my original post I get an error when accessing payload.body.trace because body does not exist on object.
TS Error:

Property 'body' does not exist on type 'object'.ts(2339)

I can work around it by typing the transform function myself like transform: function(payload: whatevertype) {...} but I thought I'd raise it here that without retyping it I get an error.
When I initially posted this I was using TypeScript 3.x but I have since upgrade to 4.6.2 and I experience the same behavior.

@waltjones
Copy link
Contributor

Fix is released in v2.26.1. Thank you for the report.

@goibon
Copy link
Author

goibon commented Jan 4, 2023

Awesome! No problem at all, I'm looking forward to upgrading 👍

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

No branches or pull requests

2 participants