Skip to content
This repository was archived by the owner on Feb 15, 2019. It is now read-only.

Commit 8fcb030

Browse files
committed
fix: not passing extra props to created component by
typescript issue in the returned function of the hoc
1 parent 5b69857 commit 8fcb030

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Diff for: src/UniformComponent.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { mount } from "enzyme"
44
import { UniformComponent, UniformProps } from "./index"
55

66
describe("<UniformComponent>", () => {
7-
class TestUniformComponent extends React.Component<UniformProps<{ bar: string }>> {
7+
class TestUniformComponent extends React.Component<
8+
UniformProps<{ bar: string }, { asdf?: string }>
9+
> {
810
render() {
911
return <input onChange={ev => this.props.data.change.bar(ev.target.value)} type="string" />
1012
}

Diff for: src/UniformComponent.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import React, { ComponentClass, SFC } from "react"
22
import Data, { IData } from "handle-data-change"
33

4-
export { IData }
5-
64
export type IProps<D, P = {}> = {
75
value: D
86
onChange?: (newValue: D) => void
97
path?: string[]
10-
} & P
8+
} & (P | {})
119

1210
export type UniformProps<D, P = {}> = {
1311
data: IData<D>
14-
} & P
12+
} & (P | {})
1513

1614
function equal<T>(a: T, b: T) {
1715
return a === b
@@ -24,7 +22,7 @@ export function UniformComponent<D, H>(
2422
let uniValue: D = {} as D
2523
let uniPath: string[]
2624
let data = new Data<D>({} as D, uniOnChange)
27-
return function<H>(props: IProps<D> & H) {
25+
return function(props: IProps<D, H>) {
2826
const { onChange, value, defaultValue, path, ...rest } = props as any
2927
if (!equal(onChange, uniOnChange) || !equal(value, uniValue) || !equal(path, uniPath)) {
3028
uniOnChange = onChange

Diff for: src/UniformSelect.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import * as React from "react"
2-
import { IProps } from "./UniformComponent"
32
import { SafeJoin, Omit } from "./type-helpers"
43

54
export type UniformOptionProps<T> = SafeJoin<JSX.IntrinsicElements["option"], { value: T }>
65

6+
type IProps<D, P = {}> = {
7+
value: D
8+
onChange?: (newValue: D) => void
9+
path?: string[]
10+
} & P
11+
712
export class UniformSelect<T extends string> extends React.Component<
813
IProps<
914
T,

0 commit comments

Comments
 (0)