Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert helpers.js to TypeScript #1156

Merged
merged 3 commits into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -65,6 +65,9 @@
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/prefer-optional-chain": "off",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistic rule whose rational is not suitable for a lint rule (false-positive rate needs to be next to zero).

"@typescript-eslint/no-explicit-any": "off",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed languages have won over JS because we have these escape hatches. They're still relevant especially in a library

"@typescript-eslint/no-unsafe-member-access": "off",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this rule can distiginguish between explicit any and implicit/external any we can disable. Until then its false-positive rate is too high.

"@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