Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit a50f183

Browse files
committed
feat(dom): Convert JS to TypeScript
Refs #4225
1 parent 8bcf546 commit a50f183

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

packages/mdc-dom/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
* THE SOFTWARE.
2222
*/
2323

24-
import * as ponyfill from './ponyfill';
24+
import * as ponyfill from './ponyfill.ts';
2525

2626
export {ponyfill};

packages/mdc-dom/ponyfill.js renamed to packages/mdc-dom/ponyfill.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
* This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
2727
*/
2828

29-
/**
30-
* @param {!Element} element
31-
* @param {string} selector
32-
* @return {?Element}
33-
*/
34-
function closest(element, selector) {
29+
interface MsElement extends Element {
30+
msMatchesSelector(selector: string): boolean;
31+
}
32+
33+
function closest(element: Element, selector: string): Element | null {
3534
if (element.closest) {
3635
return element.closest(selector);
3736
}
@@ -46,15 +45,10 @@ function closest(element, selector) {
4645
return null;
4746
}
4847

49-
/**
50-
* @param {!Element} element
51-
* @param {string} selector
52-
* @return {boolean}
53-
*/
54-
function matches(element, selector) {
48+
function matches(element: Element, selector: string): boolean {
5549
const nativeMatches = element.matches
56-
|| element.webkitMatchesSelector
57-
|| element.msMatchesSelector;
50+
|| element.webkitMatchesSelector
51+
|| (element as MsElement).msMatchesSelector;
5852
return nativeMatches.call(element, selector);
5953
}
6054

0 commit comments

Comments
 (0)