Configuration.transform incorrectly typed
goibon opened this issue · comments
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
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?
@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.
Fix is released in v2.26.1. Thank you for the report.
Awesome! No problem at all, I'm looking forward to upgrading 👍