Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Solved) Type error when passing props to customInput. V 4.9 & 5.0 Beta4 #668

Closed
armada45-pixel opened this issue Sep 10, 2022 · 1 comment

Comments

@armada45-pixel
Copy link

Describe the issue and the actual behavior

Work fine. But type error when try to passing props to customInput.
I test for version 4.9 and 5.0 beta 4

Describe the expected behavior

Fix type.

My Custom Component

import {
  Form,
  FormControlProps,
  FormGroupProps,
} from "react-bootstrap"

interface Props {
  controlId?: FormGroupProps["controlId"]
  className?: FormGroupProps["className"]
  required?: boolean
}

interface formProps extends Props {
  value?: FormControlProps["value"]
  placeholder?: FormControlProps["placeholder"]
  type?: FormControlProps["type"]
  onChange?: FormControlProps["onChange"]
  isValid?: FormControlProps["isValid"]
  isInvalid?: FormControlProps["isInvalid"]
  onBlur?: FormControlProps["onBlur"]
}

export const FormFloatingCT = (
  props: formProps = {
    controlId: "",
    className: "",
    placeholder: "",
    required: false,
    isInvalid: false,
    isValid: false,
  },
) => {
  return (
    <>
      <Form.Group
        className={"form-floating " + props.className}
        controlId={props.controlId}
      >
        <Form.Control
          value={props.value}
          onChange={props.onChange}
          placeholder={props.placeholder}
          type={props.type}
          required={props.required}
          isValid={props.isValid}
          isInvalid={props.isInvalid}
          onBlur={props.onBlur}
        />
        <Form.Label>{props.placeholder}</Form.Label>
      </Form.Group>
    </>
  )
}

My Format Component

import { PatternFormat } from "react-number-format"
function page () {
return (
<>
<PatternFormat
  id="id"
  customInput={FormFloatingCT}
  value={state.value}
  className={`mb-4`}
  format="##"
  onValueChange={(f, s) => {
    dispatch(Change(f.formattedValue))
  }}
  onBlur={(e: { target: { value: string } }) => {
    dispatch(Change(e.target.value))
  }}
  placeholder={"Text"}
  isValid={state.validation === true}
  isInvalid={
    state.validation !== false &&
    state.validation !== true
  }
 />
<>
)
}

When build type error

error TS2322: Type '{ id: string; customInput: (props?: formProps) => Element; value: string; className: string; format: string; mask: string; onValueChange: (f: NumberFormatValues, s: SourceInfo) => void; onBlur: (e: { ...; }) => void; placeholder: string; isValid: boolean; isInvalid: boolean; }' is not assignable to type 'IntrinsicAttributes & InternalNumberFormatBase & { format: string; mask?: string | string[] | undefined; allowEmptyFormatting?: boolean | undefined; patternChar?: string | undefined; } & Omit<...> & Omit<...> & { ...; }'.
  Property 'isValid' does not exist on type 'IntrinsicAttributes & InternalNumberFormatBase & { format: string; mask?: string | string[] | undefined; allowEmptyFormatting?: boolean | undefined; patternChar?: string | undefined; } & Omit<...> & Omit<...> & { ...; }'.

                       isValid={SignUpState.validation.nin === true}
                       ~~~~~~~
@armada45-pixel
Copy link
Author

Solved
#508 (comment)

@armada45-pixel armada45-pixel changed the title Type error when passing props to customInput. V 4.9 & 5.0 Beta4 Type error when passing props to customInput. V 4.9 & 5.0 Beta4 (Solved) Sep 10, 2022
@armada45-pixel armada45-pixel changed the title Type error when passing props to customInput. V 4.9 & 5.0 Beta4 (Solved) (Solved) Type error when passing props to customInput. V 4.9 & 5.0 Beta4 Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant