Skip to content

Commit

Permalink
Fix TS issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Sep 9, 2020
1 parent 502d8e6 commit afef765
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useEffect, useRef, useCallback, useMemo } from 'react';
import { FormHook, FieldConfig } from '../types';
import { getFieldValidityAndErrorMessage } from '../helpers';
import { useFormContext } from '../form_context';
import { useField } from '../hooks';
import { useField, InternalFieldConfig } from '../hooks';

interface Props {
path: string;
Expand Down Expand Up @@ -101,13 +101,13 @@ export const UseArray = ({

// Create a new hook field with the "hasValue" set to false so we don't use its value to build the final form data.
// Apart from that the field behaves like a normal field and is hooked into the form validation lifecycle.
const fieldConfigBase = {
const fieldConfigBase: FieldConfig<any, ArrayItem[]> & InternalFieldConfig<ArrayItem[]> = {
defaultValue: fieldDefaultValue,
errorDisplayDelay: 0,
hasValue: false,
isIncludedInOutput: false,
};

const fieldConfig: FieldConfig<any, ArrayItem[]> & { hasValue?: boolean } = validations
const fieldConfig: FieldConfig<any, ArrayItem[]> & InternalFieldConfig<ArrayItem[]> = validations
? { validations, ...fieldConfigBase }
: fieldConfigBase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

export { useField } from './use_field';
export { useField, InternalFieldConfig } from './use_field';
export { useForm } from './use_form';
export { useFormData } from './use_form_data';
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
import { FormHook, FieldHook, FieldConfig, FieldValidateResponse, ValidationError } from '../types';
import { FIELD_TYPES, VALIDATION_TYPES } from '../constants';

interface InternalConfig<T> {
export interface InternalFieldConfig<T> {
initialValue?: T;
isIncludedInOutput?: boolean;
}

export const useField = <T>(
form: FormHook,
path: string,
config: FieldConfig<any, T> & InternalConfig<T> = {},
config: FieldConfig<any, T> & InternalFieldConfig<T> = {},
valueChangeListener?: (value: T) => void
) => {
const {
Expand Down

0 comments on commit afef765

Please sign in to comment.