Skip to content

Commit 5c279b3

Browse files
committed
Makes the ontouch* events on window optional.
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 85ea749 commit 5c279b3

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
@@ -6096,10 +6096,10 @@ interface GlobalEventHandlers {
60966096
*/
60976097
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
60986098
ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null;
6099-
ontouchcancel: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6100-
ontouchend: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6101-
ontouchmove: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6102-
ontouchstart: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6099+
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6100+
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6101+
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
6102+
ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null;
61036103
ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
61046104
ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
61056105
ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
@@ -19886,10 +19886,10 @@ declare var onsuspend: ((this: Window, ev: Event) => any) | null;
1988619886
*/
1988719887
declare var ontimeupdate: ((this: Window, ev: Event) => any) | null;
1988819888
declare var ontoggle: ((this: Window, ev: Event) => any) | null;
19889-
declare var ontouchcancel: ((this: Window, ev: TouchEvent) => any) | null;
19890-
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null;
19891-
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null;
19892-
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null;
19889+
declare var ontouchcancel: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19890+
declare var ontouchend: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19891+
declare var ontouchmove: ((this: Window, ev: TouchEvent) => any) | null | undefined;
19892+
declare var ontouchstart: ((this: Window, ev: TouchEvent) => any) | null | undefined;
1989319893
declare var ontransitioncancel: ((this: Window, ev: TransitionEvent) => any) | null;
1989419894
declare var ontransitionend: ((this: Window, ev: TransitionEvent) => any) | null;
1989519895
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)