Skip to content

Commit

Permalink
fix: getInputProps().value type
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Aug 15, 2023
1 parent bebd998 commit d4cf03f
Show file tree
Hide file tree
Showing 3 changed files with 1,069 additions and 1,072 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
]
},
"dependencies": {
"@tanstack/store": "^0.0.1-beta.84",
"@tanstack/store": "0.0.1-beta.90",
"fs-extra": "^11.1.1",
"rollup-plugin-dts": "^5.3.0"
}
Expand Down
16 changes: 8 additions & 8 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export type ChangeProps<TData> = {
onBlur: (event: any) => void
}

export type InputProps = {
value: string
export type InputProps<T> = {
value: T
onChange: (event: any) => void
onBlur: (event: any) => void
}
Expand All @@ -81,7 +81,7 @@ export class FieldApi<TData, TFormData> {
name!: DeepKeys<TFormData>
store!: Store<FieldState<TData>>
state!: FieldState<TData>
#prevState!: FieldState<TData>
prevState!: FieldState<TData>
options: FieldOptions<TData, TFormData> = {} as any

constructor(opts: FieldApiOptions<TData, TFormData>) {
Expand Down Expand Up @@ -113,18 +113,18 @@ export class FieldApi<TData, TFormData> {
? state.meta.error
: undefined

if (state.value !== this.#prevState.value) {
if (state.value !== this.prevState.value) {
this.validate('change', state.value)
}

this.#prevState = state
this.prevState = state
this.state = state
},
},
)

this.state = this.store.state
this.#prevState = this.state
this.prevState = this.state
this.update(opts)
}

Expand Down Expand Up @@ -375,10 +375,10 @@ export class FieldApi<TData, TFormData> {

getInputProps = <T extends UserInputProps>(
props: T = {} as T,
): InputProps & Omit<T, keyof InputProps> => {
): InputProps<TData> & Omit<T, keyof InputProps<TData>> => {
return {
...props,
value: String(this.state.value),
value: this.state.value,
onChange: (e) => {
this.setValue(e.target.value)
props.onChange?.(e.target.value)
Expand Down
Loading

0 comments on commit d4cf03f

Please sign in to comment.