Skip to content

Commit

Permalink
Added never return types to selector within() signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
JJWesterkamp committed Apr 11, 2021
1 parent efdfb6b commit 061fced
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const EventDelegation: AskRoot = {
// Create one delegated event listener for a specified root element.
// ----------------------------------------------------------------------------------------

within(rootOrSelector: string | Element): AskEvent<any, 'SINGLE'> {
within(rootOrSelector: string | Element): AskEvent<any, 'SINGLE'> | never {
return createBuilder(normalizeRoot(rootOrSelector))
},

Expand Down
2 changes: 1 addition & 1 deletion src/lib/normalizeRoot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isString } from './isString'
import { isNil } from './isNil'

export function normalizeRoot<R extends Element>(rootOrSelector: string | R): R {
export function normalizeRoot<R extends Element>(rootOrSelector: string | R): R | never {
if (isString(rootOrSelector)) {
const rootOrNull = document.querySelector<R>(rootOrSelector)

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface AskRoot {
* @typeParam K the HTML tag name literal type for the selector argument.
* This param is inferred from the selector argument.
*/
within<K extends keyof TagNameMap>(selector: K): AskEvent<TagNameMap[K], 'SINGLE'>
within<K extends keyof TagNameMap>(selector: K): AskEvent<TagNameMap[K], 'SINGLE'> | never

/**
* Start building an event-delegation handler for a specified root.
Expand All @@ -127,7 +127,7 @@ export interface AskRoot {
* @typeParam R The element type for the root element.
* This param can be explicitly given to override the default `Element` type.
*/
within<R extends Element>(root: string): AskEvent<R, 'SINGLE'>
within<R extends Element>(root: string): AskEvent<R, 'SINGLE'> | never

// ------------------------------------------------------------------------------
// EventDelegation.withinMany()
Expand Down

0 comments on commit 061fced

Please sign in to comment.