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

fix: Minor typing issues for web sandbox #3660

Merged
merged 4 commits into from
Mar 8, 2023

Conversation

MSNev
Copy link
Contributor

@MSNev MSNev commented Mar 7, 2023

The web sandbox is using a later version of TypeScript and these fixes are just typing updates to allow the sandbox to merge and compile.

Short description of the changes

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested locally (on windows) and by duplicating the changed in a local sandbox branch

@MSNev MSNev requested a review from a team March 7, 2023 19:28
*/
export function isListenerObject(obj: TargetWithEvents = {}): boolean {
export function isListenerObject(obj: TargetWithEvents | 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.

Other options considered and open to

  • Change the obj type to just any function isListenerObject(obj: any = {})
  • Add a generic type with a constraint of extending TargetWithEvents, but this requires the caller to cast as any
  • Change the type checks to use "named" obj["addEventListener"] lookup as (currently) TypeScript doesn't complain on this type of lookup
  • Cast each obj as any for usage (obj as any).addEventListener (just not pretty)

Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer

  • Change the obj type to just any function isListenerObject(obj: any = {})

But it's not blocking for me. 🙂

@codecov
Copy link

codecov bot commented Mar 7, 2023

Codecov Report

Merging #3660 (fb4ea12) into main (48ecf22) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head fb4ea12 differs from pull request most recent head e55a52c. Consider uploading reports for the commit e55a52c to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3660      +/-   ##
==========================================
- Coverage   93.56%   93.55%   -0.02%     
==========================================
  Files         275      275              
  Lines        8125     8126       +1     
  Branches     1691     1691              
==========================================
  Hits         7602     7602              
- Misses        523      524       +1     
Impacted Files Coverage Δ
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 97.02% <100.00%> (ø)
...es/opentelemetry-context-zone-peer-dep/src/util.ts 100.00% <100.00%> (ø)
packages/opentelemetry-sdk-trace-web/src/utils.ts 95.06% <100.00%> (+0.03%) ⬆️
...-trace-base/src/platform/node/RandomIdGenerator.ts 87.50% <0.00%> (-6.25%) ⬇️

@@ -44,7 +44,7 @@ function getUrlNormalizingAnchor(): HTMLAnchorElement {
* @param key
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function hasKey<O>(obj: O, key: keyof any): key is keyof O {
export function hasKey<O extends object>(obj: O, key: keyof any): key is keyof O {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other options

  • cast the usage only return key in (obj as any);
  • remove the generic and just accept any for obj (not ideal)

@@ -301,7 +301,7 @@ export class FetchInstrumentation extends InstrumentationBase<
): Promise<Response> {
const self = this;
const url = web.parseUrl(
args[0] instanceof Request ? args[0].url : args[0]
args[0] instanceof Request ? args[0].url : String(args[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For later version for TypeScript the args[0] is identified as a Request, string or URL and the URL can't be passed to the parseUrl so using the String() constructor to cause the URL variant to become a string and keep TypeScript happy.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Looks good. 🙂

*/
export function isListenerObject(obj: TargetWithEvents = {}): boolean {
export function isListenerObject(obj: TargetWithEvents | any = {}): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer

  • Change the obj type to just any function isListenerObject(obj: any = {})

But it's not blocking for me. 🙂

@pichlermarc
Copy link
Member

I mentioned during the SIG meeting that I'll merge it tomorrow, but given that the changes in this PR are minimal, I'll merge this now to unblock the sandbox. 🙂

@pichlermarc pichlermarc merged commit ecb5ebe into open-telemetry:main Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants