Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` /home/runner/work/opentelemetry-js/opentelemetry-js/packages/opentelemetry-core/src/utils/lodash.merge.ts 44:24 warning Don't use `Function` as a type @typescript-eslint/ban-types ``` This could have been addressed in various ways with no change to the code, but upon further inspection, we can probably shed some weight here. This code was inherited from lodash, which defines: ```js const getPrototype = overArg(Object.getPrototypeOf, Object); ``` `overArg` allows each argument of the passed in function to be transformed by a mapper function, in this case, effective it amounts to: ```js const getPrototypeOf = Object.getPrototype; function getPrototype(value) { return getPrototypeOf(Object(value)); } ``` So at minimum, we can just inline _that_ and get rid of `overArg`, since that's the only place we use that function. The intent here appears to be making a "safe" version of `Object.getPrototypeOf` that can be called with primitive values. For example, `Object.getPrototypeOf(null)` would throw, but `Object.getPrototypeOf(Object(null))` wouldn't, and same for `1`, `true`, etc. Essentially, `Object(value)` will box the primitive value and the function will return the prototype of the boxed primitive object. I suppose this is useful in the rest of the lodash codebase. However, it's unclear that it is necessary in our stripped down version. `getPrototype` is only used in `isPlainObject`. The first thing that function does is reject any non-object values which would necessarily exclude all primitive values. So I am pretty sure the `Object()` does nothing for us and we can just call `Object.getPrototypeOf` directly and shed all the extra stuff. Ref open-telemetry#5365
- Loading branch information