Skip to content

Commit e1811c5

Browse files
MicahZoltusandersn
authored andcommitted
Makes the ontouch* events on window optional. (#749)
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.
1 parent 6a19e4e commit e1811c5

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

baselines/dom.generated.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6098,10 +6098,10 @@ interface GlobalEventHandlers {
60986098
*/
60996099
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
61006100
ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null;
6101-
ontouchcancel: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6102-
ontouchend: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6103-
ontouchmove: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6104-
ontouchstart: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6101+
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6102+
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6103+
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6104+
ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
61056105
ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
61066106
ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
61076107
ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
@@ -19888,10 +19888,10 @@ declare var onsuspend: ((this: Window, ev: Event) => any) | null;
1988819888
*/
1988919889
declare var ontimeupdate: ((this: Window, ev: Event) => any) | null;
1989019890
declare var ontoggle: ((this: Window, ev: Event) => any) | null;
19891-
declare var ontouchcancel: ((this: Window, ev: TouchEvent) => any) | null;
19892-
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null;
19893-
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null;
19894-
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null;
19891+
declare var ontouchcancel: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19892+
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19893+
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19894+
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null | undefined;
1989519895
declare var ontransitioncancel: ((this: Window, ev: TransitionEvent) => any) | null;
1989619896
declare var ontransitionend: ((this: Window, ev: TransitionEvent) => any) | null;
1989719897
declare var ontransitionrun: ((this: Window, ev: TransitionEvent) => any) | null;

inputfiles/overridingTypes.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@
129129
"property": {
130130
"onerror": {
131131
"override-type": "OnErrorEventHandler"
132+
},
133+
"ontouchcancel": {
134+
"required": 0
135+
},
136+
"ontouchend": {
137+
"required": 0
138+
},
139+
"ontouchmove": {
140+
"required": 0
141+
},
142+
"ontouchstart": {
143+
"required": 0
132144
}
133145
}
134146
}

src/emitter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,12 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
617617
else {
618618
pType = convertDomTypeToTsType(p);
619619
}
620-
const requiredModifier = p.required === undefined || p.required === 1 ? "" : "?";
620+
const required = p.required === undefined || p.required === 1;
621+
const requiredModifier = required || prefix ? "" : "?";
621622
pType = p.nullable ? makeNullable(pType) : pType;
623+
if (!required && prefix) {
624+
pType += " | undefined"
625+
}
622626
const readOnlyModifier = p["read-only"] === 1 && prefix === "" ? "readonly " : "";
623627
printer.printLine(`${prefix}${readOnlyModifier}${p.name}${requiredModifier}: ${pType};`);
624628
}

0 commit comments

Comments
 (0)