Skip to content

Commit adf6ba2

Browse files
authored
Merge pull request #44 from LeetCode-OpenSource/fix-type-voidable-callback-issue
fix(types): VoidableCallback<any> issue
2 parents 123910e + 42549fe commit adf6ba2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/use-event-callback.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { Observable, BehaviorSubject, Subject, noop } from 'rxjs'
33

44
import { RestrictArray, VoidAsNull, Not } from './type'
55

6-
type VoidableCallback<EventValue> = [EventValue] extends [void] ? () => void : (val: EventValue) => void
6+
// https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type
7+
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N
8+
9+
type IsAny<T> = IfAny<T, true, false>
10+
11+
type IsVoid<T> = IsAny<T> extends true ? false : [T] extends [void] ? true : false
12+
13+
type VoidableCallback<EventValue> = IsVoid<EventValue> extends true ? () => void : (val: EventValue) => void
714

815
export type EventCallbackState<EventValue, State, Inputs = void> = [
916
VoidableCallback<EventValue>,

0 commit comments

Comments
 (0)