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

Commit

Permalink
feat(dom): Convert JS to TypeScript
Browse files Browse the repository at this point in the history
Refs #4225
  • Loading branch information
acdvorak committed Jan 18, 2019
1 parent 8bcf546 commit a50f183
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/mdc-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* THE SOFTWARE.
*/

import * as ponyfill from './ponyfill';
import * as ponyfill from './ponyfill.ts';

export {ponyfill};
22 changes: 8 additions & 14 deletions packages/mdc-dom/ponyfill.js → packages/mdc-dom/ponyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
* This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
*/

/**
* @param {!Element} element
* @param {string} selector
* @return {?Element}
*/
function closest(element, selector) {
interface MsElement extends Element {
msMatchesSelector(selector: string): boolean;
}

function closest(element: Element, selector: string): Element | null {
if (element.closest) {
return element.closest(selector);
}
Expand All @@ -46,15 +45,10 @@ function closest(element, selector) {
return null;
}

/**
* @param {!Element} element
* @param {string} selector
* @return {boolean}
*/
function matches(element, selector) {
function matches(element: Element, selector: string): boolean {
const nativeMatches = element.matches
|| element.webkitMatchesSelector
|| element.msMatchesSelector;
|| element.webkitMatchesSelector
|| (element as MsElement).msMatchesSelector;
return nativeMatches.call(element, selector);
}

Expand Down

0 comments on commit a50f183

Please sign in to comment.