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

refactor(context-zone-peer-dep): fix eslint warnings #5371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/opentelemetry-context-zone-peer-dep/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
*/

/**
* check if an object has addEventListener and removeEventListener functions then it will return true.
* Generally only called with a `TargetWithEvents` but may be called with an unknown / any.
* check if an object has `addEventListener` and `removeEventListener` functions.
* Generally only called with a `TargetWithEvents` but may be called with an `unknown` value.
* @param obj - The object to check.
*/
export function isListenerObject(obj: any = {}): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter default seems pointless as that will just always return false. Removed it since this is a private utility not a public export.

export function isListenerObject(obj: unknown): boolean {
return (
typeof obj === 'object' &&
obj !== null &&
'addEventListener' in obj &&
typeof obj.addEventListener === 'function' &&
'removeEventListener' in obj &&
typeof obj.removeEventListener === 'function'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are alternatives without changing the runtime code (which can impose a small runtime cost), but this seemed the most straightforward/clear, and doesn't seem like the micro performance cost should matter all that much.

);
}
Loading