-
Notifications
You must be signed in to change notification settings - Fork 462
Description
Looking through the code, there is this line (repeated a few times)
- We have
sumwhich is a number (defined above aslet sum = 0. sumShiftcan be undefined. This can be solved earlier in the code withconst { count, sumValues, sumShift = 0 } = options;firstValueis returned fromdecoder.readValue()that has way too many types: string, number, null, undefined, void
A little cleanup in the decoder reduces the return types to string | number | null filtering down to the line in question where firstValue can be of a number or string type.
anyString >>> anyNumber has a lot of side effects. It really just depends if the value can be cast to a number. If it can be cast, it will work as expected. If it can't it will return 0. Returning zero isn't probably correct as sum will not be incremented as a number would. Worse though, if sum += sumShift is falsey, then we end up with sum adding a string to 0. Now we aren't a number but 0some-text-string.
Am I wrong here? Or does the RLEEncoder basically incorrectly generate the sum of strings when using sumValues?