Skip to content

Commit 277a4fb

Browse files
erikras-gilfoyle-agentErik Rasmussen
andauthored
fix: Remove HTMLElement constraint for React Native compatibility (#1065)
* Fix: Remove HTMLElement constraint for React Native compatibility Fixes #1051 Changes: - Remove 'T extends HTMLElement' constraint from FieldInputProps, FieldRenderProps, and FieldProps - Change to 'T = any' to support both React DOM and React Native - Re-export FieldMetaState type for backwards compatibility (was removed in v7.0.0) This allows React Native users to use react-final-form without TypeScript errors while maintaining full backwards compatibility with React DOM users. * fix: Update TypeScript declarations to match React Native type changes - Change generic constraint from 'T extends HTMLElement = HTMLElement' to 'T = any' - Add FieldMetaState type export for backwards compatibility - Sync all type declarations with src/types.ts changes * docs: Clarify FieldMetaState comment per CodeRabbit feedback Changed comment from '(removed in v7.0.0)' which reads like a future removal, to clarify it was removed from sources but re-exported here for backwards compatibility. --------- Co-authored-by: Erik Rasmussen <erik@mini.local>
1 parent ab46e1e commit 277a4fb

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ReactContext<FormValues = Record<string, any>> {
1717

1818
export interface FieldInputProps<
1919
FieldValue = any,
20-
T extends HTMLElement = HTMLElement,
20+
T = any,
2121
> {
2222
name: string;
2323
onBlur: (event?: React.FocusEvent<T>) => void;
@@ -31,7 +31,7 @@ export interface FieldInputProps<
3131

3232
export interface FieldRenderProps<
3333
FieldValue = any,
34-
T extends HTMLElement = HTMLElement,
34+
T = any,
3535
_FormValues = any,
3636
> {
3737
input: FieldInputProps<FieldValue, T>;
@@ -58,6 +58,10 @@ export interface FieldRenderProps<
5858
};
5959
}
6060

61+
// Re-export of FieldMetaState for backwards compatibility
62+
// (removed from original sources in v7.0.0 but re-exported here)
63+
export type FieldMetaState<FieldValue = any> = FieldRenderProps<FieldValue>['meta'];
64+
6165
export interface SubmitEvent {
6266
preventDefault?: () => void;
6367
stopPropagation?: () => void;
@@ -120,7 +124,7 @@ export interface UseFieldConfig extends UseFieldAutoConfig {
120124

121125
export interface FieldProps<
122126
FieldValue = any,
123-
T extends HTMLElement = HTMLElement,
127+
T = any,
124128
_FormValues = Record<string, any>,
125129
> extends UseFieldConfig,
126130
Omit<RenderableProps<FieldRenderProps<FieldValue, T>>, "children"> {

typescript/index.d.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ReactContext<FormValues = Record<string, any>> {
1717

1818
export interface FieldInputProps<
1919
FieldValue = any,
20-
T extends HTMLElement = HTMLElement,
20+
T = any,
2121
> {
2222
name: string;
2323
onBlur: (event?: React.FocusEvent<T>) => void;
@@ -31,7 +31,7 @@ export interface FieldInputProps<
3131

3232
export interface FieldRenderProps<
3333
FieldValue = any,
34-
T extends HTMLElement = HTMLElement,
34+
T = any,
3535
_FormValues = any,
3636
> {
3737
input: FieldInputProps<FieldValue, T>;
@@ -58,6 +58,10 @@ export interface FieldRenderProps<
5858
};
5959
}
6060

61+
// Re-export of FieldMetaState for backwards compatibility
62+
// (removed from original sources in v7.0.0 but re-exported here)
63+
export type FieldMetaState<FieldValue = any> = FieldRenderProps<FieldValue>['meta'];
64+
6165
export interface SubmitEvent {
6266
preventDefault?: () => void;
6367
stopPropagation?: () => void;
@@ -119,7 +123,7 @@ export interface UseFieldConfig extends UseFieldAutoConfig {
119123

120124
export interface FieldProps<
121125
FieldValue = any,
122-
T extends HTMLElement = HTMLElement,
126+
T = any,
123127
_FormValues = Record<string, any>,
124128
> extends UseFieldConfig,
125129
Omit<RenderableProps<FieldRenderProps<FieldValue, T>>, "children"> {
@@ -145,7 +149,7 @@ export interface FormSpyPropsWithForm<FormValues = Record<string, any>>
145149

146150
export const Field: <
147151
FieldValue = any,
148-
T extends HTMLElement = HTMLElement,
152+
T = any,
149153
FormValues = Record<string, any>,
150154
>(
151155
props: FieldProps<FieldValue, T, FormValues>,
@@ -161,7 +165,7 @@ export const FormSpy: <FormValues = Record<string, any>>(
161165

162166
export function useField<
163167
FieldValue = any,
164-
T extends HTMLElement = HTMLElement,
168+
T = any,
165169
FormValues = Record<string, any>,
166170
>(
167171
name: string,

0 commit comments

Comments
 (0)