Skip to content

Commit

Permalink
fix: types too strict
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jul 28, 2023
1 parent 6eb0e42 commit 2c135fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
17 changes: 4 additions & 13 deletions src/index.ts
@@ -1,34 +1,25 @@
import { useCallback, useRef, useState } from 'react';

export type Handler<TProp = any> = (prop: TProp, ...args: any[]) => any;
export type Handler = (value: any, ...args: any[]) => any;

export function defaultKey(key: string) {
return 'default' + key.charAt(0).toUpperCase() + key.substr(1);
}

function useUncontrolledProp<
TProp,
THandler extends Handler<TProp> = Handler<TProp>
>(
function useUncontrolledProp<TProp, THandler extends Handler = Handler>(
propValue: TProp | undefined,
defaultValue: TProp,
handler?: THandler
): readonly [TProp, THandler];
function useUncontrolledProp<
TProp,
THandler extends Handler<TProp> = Handler<TProp>
>(
function useUncontrolledProp<TProp, THandler extends Handler = Handler>(
propValue: TProp | undefined,
defaultValue?: TProp | undefined,
handler?: THandler
): readonly [
TProp | undefined,
(...args: Parameters<THandler>) => ReturnType<THandler> | void
];
function useUncontrolledProp<
TProp,
THandler extends Handler<TProp> = Handler<TProp>
>(
function useUncontrolledProp<TProp, THandler extends Handler = Handler>(
propValue: TProp | undefined,
defaultValue: TProp | undefined,
handler?: THandler
Expand Down
9 changes: 0 additions & 9 deletions test/types-test.tsx
Expand Up @@ -28,15 +28,6 @@ function Foo2(props: Props2) {
props.defaultValue,
props.onChange
);

const onChangeBad = null as any as (value: number) => void;

const [value2, onChange2] = useUncontrolledProp(
props.value,
props.defaultValue,
// $ExpectError
onChangeBad
);
}

function FooA(props: Props) {
Expand Down

0 comments on commit 2c135fb

Please sign in to comment.