-
Notifications
You must be signed in to change notification settings - Fork 812
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
Conversation
*/ | ||
export function isListenerObject(obj: TargetWithEvents = {}): boolean { | ||
export function isListenerObject(obj: TargetWithEvents | any = {}): boolean { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 Report
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
|
@@ -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 { |
There was a problem hiding this comment.
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
forobj
(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]) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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. 🙂
33b68e0
to
e55a52c
Compare
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. 🙂 |
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.
How Has This Been Tested?
Tested locally (on windows) and by duplicating the changed in a local sandbox branch