You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to create a React component that returns a ReactFormExtendedApi.Form component containing an <input> field, passing down to that input some attributes such as the value (field.state.value) and onChange function (field.handleChange(v)).
Since this component returns an input field, it should accept only form keys whose value is of type string in the current form.
I am having problems in achieving that with TypeScript. This is the FormInput code:
As you can see, there is a type (TypedDeepKeys) that should narrow the accepted keys of the form schema to those that accept a string value.
However, it seems that TypeScript does not recognize that with this constraint the field.state.value can only be a string, as I get the following error:
Type 'DeepValue<FormData, K, IsNullable<FormData>>' is not assignable to type 'string | number | readonly string[] | undefined'.
Type 'FormData | (FormData extends readonly any[] ? K extends `[${infer TBrackets}].${infer TAfter}` ? DeepValue<DeepValue<FormData, TBrackets, IsNullable<FormData>>, TAfter, IsNullable<...>> : K extends `[${infer TBrackets}]` ? DeepValue<...> : K extends keyof FormData ? FormData[K] : FormData[K & number] : FormData exte...' is not assignable to type 'string | number | readonly string[] | undefined'.
Type 'FormData' is not assignable to type 'string | number | readonly string[] | undefined'.
Type 'FormData' is not assignable to type 'readonly string[]'.
Type 'DeepValue<FormData, K, IsNullable<FormData>>' is not assignable to type 'readonly string[]'.
Type 'FormData | (FormData extends readonly any[] ? K extends `[${infer TBrackets}].${infer TAfter}` ? DeepValue<DeepValue<FormData, TBrackets, IsNullable<FormData>>, TAfter, IsNullable<...>> : K extends `[${infer TBrackets}]` ? DeepValue<...> : K extends keyof FormData ? FormData[K] : FormData[K & number] : FormData exte...' is not assignable to type 'readonly string[]'.
Type 'FormData' is not assignable to type 'readonly string[]'.
Looks like that the type of field.state.value may also be FormData, but this doesn't make sense.
Is there something that I'm missing?
The text was updated successfully, but these errors were encountered:
I would like to create a React component that returns a
ReactFormExtendedApi.Form
component containing an<input>
field, passing down to that input some attributes such as the value (field.state.value) and onChange function (field.handleChange(v)).Since this component returns an input field, it should accept only form keys whose value is of type string in the current form.
I am having problems in achieving that with TypeScript. This is the FormInput code:
As you can see, there is a type (TypedDeepKeys) that should narrow the accepted keys of the form schema to those that accept a string value.
However, it seems that TypeScript does not recognize that with this constraint the
field.state.value
can only be a string, as I get the following error:Looks like that the type of field.state.value may also be FormData, but this doesn't make sense.
Is there something that I'm missing?
The text was updated successfully, but these errors were encountered: