Skip to content

Commit 13efbb3

Browse files
authored
chore: Remove unused Nullish type (#953)
1 parent e061cd1 commit 13efbb3

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

src/label-helpers.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {Nullish} from '../types'
21
import {TEXT_NODE} from './helpers'
32

43
const labelledNodeNames = [
@@ -25,7 +24,7 @@ function getTextContent(
2524
.join('')
2625
}
2726

28-
function getLabelContent(element: Element): Nullish<string> {
27+
function getLabelContent(element: Element): string | null {
2928
let textContent: string | null
3029
if (element.tagName.toLowerCase() === 'label') {
3130
textContent = getTextContent(element)
@@ -59,7 +58,7 @@ function getLabels(
5958
container: Element,
6059
element: Element,
6160
{selector = '*'} = {},
62-
): {content: Nullish<string>; formControl: Nullish<HTMLElement>}[] {
61+
): {content: string | null; formControl: HTMLElement | null}[] {
6362
const ariaLabelledBy = element.getAttribute('aria-labelledby')
6463
const labelsId = ariaLabelledBy ? ariaLabelledBy.split(' ') : []
6564
return labelsId.length

src/matches.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
DefaultNormalizerOptions,
66
} from '../types'
77

8-
type Nullish<T> = T | null | undefined
9-
108
function assertNotNullOrUndefined<T>(
119
matcher: T,
1210
): asserts matcher is NonNullable<T> {
@@ -19,9 +17,9 @@ function assertNotNullOrUndefined<T>(
1917
}
2018

2119
function fuzzyMatches(
22-
textToMatch: Nullish<string>,
23-
node: Nullish<Element>,
24-
matcher: Nullish<Matcher>,
20+
textToMatch: string | null,
21+
node: Element | null,
22+
matcher: Matcher | null,
2523
normalizer: NormalizerFn,
2624
) {
2725
if (typeof textToMatch !== 'string') {
@@ -43,9 +41,9 @@ function fuzzyMatches(
4341
}
4442

4543
function matches(
46-
textToMatch: Nullish<string>,
47-
node: Nullish<Element>,
48-
matcher: Nullish<Matcher>,
44+
textToMatch: string | null,
45+
node: Element | null,
46+
matcher: Matcher | null,
4947
normalizer: NormalizerFn,
5048
) {
5149
if (typeof textToMatch !== 'string') {

src/queries/label-text.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {getConfig} from '../config'
22
import {checkContainerType} from '../helpers'
33
import {getLabels, getRealLabels, getLabelContent} from '../label-helpers'
4-
import {AllByText, GetErrorFunction, Nullish} from '../../types'
4+
import {AllByText, GetErrorFunction} from '../../types'
55
import {
66
fuzzyMatches,
77
matches,
@@ -15,7 +15,7 @@ import {
1515

1616
function queryAllLabels(
1717
container: HTMLElement,
18-
): {textToMatch: Nullish<string>; node: HTMLElement}[] {
18+
): {textToMatch: string | null; node: HTMLElement}[] {
1919
return Array.from(container.querySelectorAll<HTMLElement>('label,input'))
2020
.map(node => {
2121
return {node, textToMatch: getLabelContent(node)}
@@ -160,7 +160,7 @@ const getAllByLabelText: AllByText = (container, text, ...rest) => {
160160
function getTagNameOfElementAssociatedWithLabelViaFor(
161161
container: Element,
162162
label: Element,
163-
): Nullish<string> {
163+
): string | null {
164164
const htmlFor = label.getAttribute('for')
165165
if (!htmlFor) {
166166
return null

types/matches.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import {ARIARole} from 'aria-query'
22

3-
type Nullish<T> = T | null | undefined
4-
53
export type MatcherFunction = (
64
content: string,
7-
element: Nullish<Element>,
5+
element: Element | null,
86
) => boolean
97
export type Matcher = MatcherFunction | RegExp | number | string
108

types/query-helpers.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Matcher, MatcherOptions, Nullish} from './matches'
1+
import {Matcher, MatcherOptions} from './matches'
22
import {waitForOptions} from './wait-for'
33

4-
export type GetErrorFunction = (c: Nullish<Element>, alt: string) => string
4+
export type GetErrorFunction = (c: Element | null, alt: string) => string
55

66
export interface SelectorMatcherOptions extends MatcherOptions {
77
selector?: string

0 commit comments

Comments
 (0)