-
Notifications
You must be signed in to change notification settings - Fork 444
Makes the ontouch*
events on window optional.
#749
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
Conversation
This makes sense, want to update the snapshots and this can be merged? |
How does one "update the snapshots"? Is that a fancy way of saying "rebase on master"? |
Ah, you are probably referring to the instructions here? https://github.com/microsoft/TSJS-lib-generator#contribution-guidelines It makes me sad that those aren't done automatically as part of CI/CD. 😢 It means I'll have to actually clone this project to make this PR rather than just doing it in the GitHub UI. |
Hmm, digging in on this it seems I need to add an |
I have rebased the PR and applied the necessary change to |
inputfiles/overridingTypes.json
Outdated
@@ -129,6 +129,18 @@ | |||
"property": { | |||
"onerror": { | |||
"override-type": "OnErrorEventHandler" | |||
}, | |||
"ontouchcancel": { | |||
"override-type": "((this: Window, ev: TouchEvent) => any) | null | undefined" |
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.
Try replacing this line with nullable: 1
.
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.
Of course, why didn't I think that nullable: 1
would change a nullable
type into a nullable | undefined
type...
Rebased again and updated to use |
You also need to run |
Bleck. I cannot run |
Ah, easy enough to replicate the |
Could you try |
|
This PR now unexpectedly is no-op 🤯 I think what we want to do here is marking it as |
inputfiles/overridingTypes.json
Outdated
@@ -129,6 +129,18 @@ | |||
"property": { | |||
"onerror": { | |||
"override-type": "OnErrorEventHandler" | |||
}, | |||
"ontouchcancel": { | |||
"nullable": 1 |
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 got an ugly working hack: Try replacing this line with "name": "ontouchcancel?"
and so on. This hack is currently being used for nonce?
.
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.
Hmm, I could have sworn that it was not a no-op when I committed...
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.
Ewe.... that is dirty... but it appears to work. Pushed.
baselines/dom.generated.d.ts
Outdated
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null; | ||
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null; | ||
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null; | ||
declare var ontouchcancel?: ((this: Window, ev: TouchEvent) => any) | null; |
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.
Ah, no, this won't work.... Sorry to make you break code 🙄
It seems we need to modify emitter to support this properly.
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.
Should I let this PR lapse until such work is complete, or return to the original solution that will break if the auto-generated types ever change?
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.
Okay, I got a working way. Please fix src/emitter.ts
line 620 as:
- const requiredModifier = p.required === undefined || p.required === 1 ? "" : "?";
+ const requiredModifier = p.required === undefined || p.required === 1 || prefix ? "" : "?";
And use required: 0
on overridingTypes.json
. I tried it and it works this time!
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.
That change doesn't appear to update the global variables:
declare var ontouchcancel: ((this: Window, ev: TouchEvent) => any) | null;
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null;
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null;
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null;
Those need to be |undefined
as well I believe?
in Firefox if you do >> ontouchcancel
you get
ReferenceError: ontouchcancel is not defined
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.
Updated PR with your suggested changes in case that is desired behavior.
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.
Ah, you're right. We can modify it further:
}
- const requiredModifier = p.required === undefined || p.required === 1 ? "" : "?";
+ const required = p.required === undefined || p.required === 1;
+ const requiredModifier = required || prefix ? "" : "?";
pType = p.nullable ? makeNullable(pType) : pType;
+ if (!required && prefix) {
+ pType += " | undefined"
+ }
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.
Updated. I look forward to the day when someone git-blames me for this and I have no idea what any of it does. 😛
Browsers without touch support (e.g., Firefox/Chrome on desktop) will not have `ontouch*` events defined on `window`, so the current type definition is not correct. package-lock was out of date and auto-updated on `npm install`. I can roll that back if desired.
Do we still need this PR if feature detection code like |
I'm not familiar with the feature detection code you are referring to, but the current definition of |
I'm not sure the current types can break things given that the if (window.ontouchstart === undefined) {
window.ontouchstart // currently this becomes never
} This is the only weird thing I could find now but it shouldn't break anything. |
The current problem is that declare const myWindow: Window
myWindow.ontouchstart(...) // should error at compile time with calling possibly undefined |
It will, because it's a union with |
Ah, good point. However, in a desktop browser with no touch interface, declare const touchEvent: TouchEvent
declare const myWindow: Window
if (myWindow.ontouchcancel !== null) {
myWindow.ontouchcancel(touchEvent)
} |
Hmmm technically yes... but why would anyone directly call a event listener? |
🤷♂ |
Seem reasonable to make it correct. If there are unforeseen problems that people run into, we have enough time to revert this change before 3.8. |
Browsers without touch support (e.g., Firefox/Chrome on desktop) will not have
ontouch*
events defined onwindow
, so the current type definition is not correct.