Skip to content

Commit

Permalink
chore: convert helpers.js to TypeScript (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Aug 9, 2022
1 parent d50a967 commit a21bb3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -65,6 +65,9 @@
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/prefer-optional-chain": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/prefer-includes": "off",
"import/prefer-default-export": "off",
"import/no-unassigned-import": "off",
Expand Down
13 changes: 7 additions & 6 deletions src/helpers.js → src/helpers.ts
Expand Up @@ -4,10 +4,11 @@ const TEXT_NODE = 3

function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
// eslint-disable-next-line
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true ||
(setTimeout as any)._isMockFunction === true ||
// modern timers
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
)
Expand All @@ -23,7 +24,7 @@ function getDocument() {
}
return window.document
}
function getWindowFromNode(node) {
function getWindowFromNode(node: any) {
if (node.defaultView) {
// node is document
return node.defaultView
Expand Down Expand Up @@ -60,11 +61,11 @@ function getWindowFromNode(node) {
}
}

function checkContainerType(container) {
function checkContainerType(container: unknown) {
if (
!container ||
!(typeof container.querySelector === 'function') ||
!(typeof container.querySelectorAll === 'function')
!(typeof (container as any).querySelector === 'function') ||
!(typeof (container as any).querySelectorAll === 'function')
) {
throw new TypeError(
`Expected container to be an Element, a Document or a DocumentFragment but got ${getTypeName(
Expand All @@ -73,7 +74,7 @@ function checkContainerType(container) {
)
}

function getTypeName(object) {
function getTypeName(object: unknown) {
if (typeof object === 'object') {
return object === null ? 'null' : object.constructor.name
}
Expand Down

0 comments on commit a21bb3d

Please sign in to comment.