Skip to content

Commit

Permalink
refactor(sdk-trace-web): fix eslint warning
Browse files Browse the repository at this point in the history
```
/home/runner/work/opentelemetry-js/opentelemetry-js/packages/opentelemetry-sdk-trace-web/src/utils.ts
  52:14  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
```

The eslint comment wasn't working because it was placed on the
wrong line. However, it also wasn't necessary anymore – `keyof any`
was used to obtain the union of all possible object key types –
`string | number | symbol`. TypeScript now provides an alias for
this in the standard libaray that gives exactly the same result.

Also fixed what appears to be a TypeError on an un-annotated `let`
binding, not sure why it wasn't caught by the type checker, maybe
it was just missed on the version of TS we are using.

Ref open-telemetry#5365
  • Loading branch information
chancancode committed Jan 28, 2025
1 parent 199fd8d commit 8ef7e8b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/opentelemetry-sdk-trace-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ function getUrlNormalizingAnchor(): HTMLAnchorElement {
* @param obj
* @param key
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function hasKey<O extends object>(
obj: O,
key: keyof any
key: PropertyKey
): key is keyof O {
return key in obj;
}
Expand All @@ -67,8 +66,8 @@ export function addSpanNetworkEvent(
entries: PerformanceEntries,
refPerfName?: string
): api.Span | undefined {
let perfTime = undefined;
let refTime = undefined;
let perfTime: number | undefined;
let refTime: number | undefined;
if (
hasKey(entries, performanceName) &&
typeof entries[performanceName] === 'number'
Expand Down

0 comments on commit 8ef7e8b

Please sign in to comment.