Skip to content

chore: Remove unused Nullish type #953

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

Merged
merged 1 commit into from
May 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/label-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Nullish} from '../types'
import {TEXT_NODE} from './helpers'

const labelledNodeNames = [
Expand All @@ -25,7 +24,7 @@ function getTextContent(
.join('')
}

function getLabelContent(element: Element): Nullish<string> {
function getLabelContent(element: Element): string | null {
let textContent: string | null
if (element.tagName.toLowerCase() === 'label') {
textContent = getTextContent(element)
Expand Down Expand Up @@ -59,7 +58,7 @@ function getLabels(
container: Element,
element: Element,
{selector = '*'} = {},
): {content: Nullish<string>; formControl: Nullish<HTMLElement>}[] {
): {content: string | null; formControl: HTMLElement | null}[] {
const ariaLabelledBy = element.getAttribute('aria-labelledby')
const labelsId = ariaLabelledBy ? ariaLabelledBy.split(' ') : []
return labelsId.length
Expand Down
14 changes: 6 additions & 8 deletions src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
DefaultNormalizerOptions,
} from '../types'

type Nullish<T> = T | null | undefined

function assertNotNullOrUndefined<T>(
matcher: T,
): asserts matcher is NonNullable<T> {
Expand All @@ -19,9 +17,9 @@ function assertNotNullOrUndefined<T>(
}

function fuzzyMatches(
textToMatch: Nullish<string>,
node: Nullish<Element>,
matcher: Nullish<Matcher>,
textToMatch: string | null,
node: Element | null,
matcher: Matcher | null,
normalizer: NormalizerFn,
) {
if (typeof textToMatch !== 'string') {
Expand All @@ -43,9 +41,9 @@ function fuzzyMatches(
}

function matches(
textToMatch: Nullish<string>,
node: Nullish<Element>,
matcher: Nullish<Matcher>,
textToMatch: string | null,
node: Element | null,
matcher: Matcher | null,
normalizer: NormalizerFn,
) {
if (typeof textToMatch !== 'string') {
Expand Down
6 changes: 3 additions & 3 deletions src/queries/label-text.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,7 +15,7 @@ import {

function queryAllLabels(
container: HTMLElement,
): {textToMatch: Nullish<string>; node: HTMLElement}[] {
): {textToMatch: string | null; node: HTMLElement}[] {
return Array.from(container.querySelectorAll<HTMLElement>('label,input'))
.map(node => {
return {node, textToMatch: getLabelContent(node)}
Expand Down Expand Up @@ -160,7 +160,7 @@ const getAllByLabelText: AllByText = (container, text, ...rest) => {
function getTagNameOfElementAssociatedWithLabelViaFor(
container: Element,
label: Element,
): Nullish<string> {
): string | null {
const htmlFor = label.getAttribute('for')
if (!htmlFor) {
return null
Expand Down
4 changes: 1 addition & 3 deletions types/matches.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {ARIARole} from 'aria-query'

type Nullish<T> = T | null | undefined

export type MatcherFunction = (
content: string,
element: Nullish<Element>,
element: Element | null,
) => boolean
export type Matcher = MatcherFunction | RegExp | number | string

Expand Down
4 changes: 2 additions & 2 deletions types/query-helpers.d.ts
Original file line number Diff line number Diff line change
@@ -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<Element>, alt: string) => string
export type GetErrorFunction = (c: Element | null, alt: string) => string

export interface SelectorMatcherOptions extends MatcherOptions {
selector?: string
Expand Down