From 13efbb3b1d63cbdde8b5b02cd52ff523287481d6 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 6 May 2021 16:29:52 +0200 Subject: [PATCH] chore: Remove unused Nullish type (#953) --- src/label-helpers.ts | 5 ++--- src/matches.ts | 14 ++++++-------- src/queries/label-text.ts | 6 +++--- types/matches.d.ts | 4 +--- types/query-helpers.d.ts | 4 ++-- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/label-helpers.ts b/src/label-helpers.ts index 720e9202..4e1a3fed 100644 --- a/src/label-helpers.ts +++ b/src/label-helpers.ts @@ -1,4 +1,3 @@ -import {Nullish} from '../types' import {TEXT_NODE} from './helpers' const labelledNodeNames = [ @@ -25,7 +24,7 @@ function getTextContent( .join('') } -function getLabelContent(element: Element): Nullish { +function getLabelContent(element: Element): string | null { let textContent: string | null if (element.tagName.toLowerCase() === 'label') { textContent = getTextContent(element) @@ -59,7 +58,7 @@ function getLabels( container: Element, element: Element, {selector = '*'} = {}, -): {content: Nullish; formControl: Nullish}[] { +): {content: string | null; formControl: HTMLElement | null}[] { const ariaLabelledBy = element.getAttribute('aria-labelledby') const labelsId = ariaLabelledBy ? ariaLabelledBy.split(' ') : [] return labelsId.length diff --git a/src/matches.ts b/src/matches.ts index 5e27ad3e..b649cb69 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -5,8 +5,6 @@ import { DefaultNormalizerOptions, } from '../types' -type Nullish = T | null | undefined - function assertNotNullOrUndefined( matcher: T, ): asserts matcher is NonNullable { @@ -19,9 +17,9 @@ function assertNotNullOrUndefined( } function fuzzyMatches( - textToMatch: Nullish, - node: Nullish, - matcher: Nullish, + textToMatch: string | null, + node: Element | null, + matcher: Matcher | null, normalizer: NormalizerFn, ) { if (typeof textToMatch !== 'string') { @@ -43,9 +41,9 @@ function fuzzyMatches( } function matches( - textToMatch: Nullish, - node: Nullish, - matcher: Nullish, + textToMatch: string | null, + node: Element | null, + matcher: Matcher | null, normalizer: NormalizerFn, ) { if (typeof textToMatch !== 'string') { diff --git a/src/queries/label-text.ts b/src/queries/label-text.ts index 0d25c880..0b59d253 100644 --- a/src/queries/label-text.ts +++ b/src/queries/label-text.ts @@ -1,7 +1,7 @@ import {getConfig} from '../config' import {checkContainerType} from '../helpers' import {getLabels, getRealLabels, getLabelContent} from '../label-helpers' -import {AllByText, GetErrorFunction, Nullish} from '../../types' +import {AllByText, GetErrorFunction} from '../../types' import { fuzzyMatches, matches, @@ -15,7 +15,7 @@ import { function queryAllLabels( container: HTMLElement, -): {textToMatch: Nullish; node: HTMLElement}[] { +): {textToMatch: string | null; node: HTMLElement}[] { return Array.from(container.querySelectorAll('label,input')) .map(node => { return {node, textToMatch: getLabelContent(node)} @@ -160,7 +160,7 @@ const getAllByLabelText: AllByText = (container, text, ...rest) => { function getTagNameOfElementAssociatedWithLabelViaFor( container: Element, label: Element, -): Nullish { +): string | null { const htmlFor = label.getAttribute('for') if (!htmlFor) { return null diff --git a/types/matches.d.ts b/types/matches.d.ts index 85e9c9a7..13fa3692 100644 --- a/types/matches.d.ts +++ b/types/matches.d.ts @@ -1,10 +1,8 @@ import {ARIARole} from 'aria-query' -type Nullish = T | null | undefined - export type MatcherFunction = ( content: string, - element: Nullish, + element: Element | null, ) => boolean export type Matcher = MatcherFunction | RegExp | number | string diff --git a/types/query-helpers.d.ts b/types/query-helpers.d.ts index a01462d1..28db0a31 100644 --- a/types/query-helpers.d.ts +++ b/types/query-helpers.d.ts @@ -1,7 +1,7 @@ -import {Matcher, MatcherOptions, Nullish} from './matches' +import {Matcher, MatcherOptions} from './matches' import {waitForOptions} from './wait-for' -export type GetErrorFunction = (c: Nullish, alt: string) => string +export type GetErrorFunction = (c: Element | null, alt: string) => string export interface SelectorMatcherOptions extends MatcherOptions { selector?: string