Skip to content

Commit 8896cf8

Browse files
committed
fix: typescript definitions
1 parent 4744b2b commit 8896cf8

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/index.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as React from 'react'
1+
import React from 'react'
22
import { ReactNode, ReactElement } from 'react'
33

44
const { values, keys, assign } = Object
55

6-
export type ChildrenFn<P> = (props: P) => ReactNode
6+
export declare type ChildrenFn<P> = (props: P) => JSX.Element | null
77

88
function omit<R = object>(omitProps: string[], obj: any): R {
99
const newObj = keys(obj)
@@ -25,23 +25,26 @@ const isFn = (val: any): boolean => Boolean(val) && typeof val === 'function'
2525
const isValidRenderProp = (prop: ReactNode | ChildrenFn<any>): boolean =>
2626
React.isValidElement(prop) || isFn(prop)
2727

28-
export type RPC<RP, P = {}> = React.SFC<
28+
export declare type RPC<RP, P = {}> = React.SFC<
2929
P & {
3030
children: ChildrenFn<RP>
3131
}
3232
>
3333

34-
export type MapperComponent<RP, P = {}> = React.SFC<
35-
P & {
36-
render?: ChildrenFn<RP & P>
37-
}
34+
export declare type MapperComponent<RP, P> = React.SFC<
35+
RP &
36+
P & {
37+
render?: ChildrenFn<any>
38+
}
3839
>
3940

40-
export type MapperValue<RP, P> = ReactElement<any> | MapperComponent<RP, P>
41+
export declare type MapperValue<RP, P> =
42+
| ReactElement<any>
43+
| MapperComponent<RP, P>
4144

42-
export type Mapper<RP, P> = Record<keyof RP, MapperValue<RP, P>>
45+
export declare type Mapper<RP, P> = Record<keyof RP, MapperValue<RP, P>>
4346

44-
export function adopt<RP = any, P = {}>(mapper: Mapper<RP, P>): RPC<RP, P> {
47+
export function adopt<RP = any, P = any>(mapper: Mapper<RP, P>): RPC<RP, P> {
4548
if (!values(mapper).some(isValidRenderProp)) {
4649
throw new Error(
4750
'The render props object mapper just accept valid elements as value'
@@ -61,12 +64,13 @@ export function adopt<RP = any, P = {}>(mapper: Mapper<RP, P>): RPC<RP, P> {
6164
const propsWithoutRest = omit<RP>(keys(rest), props)
6265

6366
const render: ChildrenFn<RP> = cProps =>
64-
isFn(children) &&
65-
children(
66-
assign({}, propsWithoutRest, {
67-
[key]: cProps,
68-
})
69-
)
67+
isFn(children)
68+
? children(
69+
assign({}, propsWithoutRest, {
70+
[key]: cProps,
71+
})
72+
)
73+
: null
7074

7175
return isFn(element)
7276
? React.createElement(element, assign({}, rest, props, { render }))

0 commit comments

Comments
 (0)