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

Property 'isValid' does not exist on type 'TextInputMask' #241

Open
euZebe opened this issue Dec 17, 2020 · 1 comment
Open

Property 'isValid' does not exist on type 'TextInputMask' #241

euZebe opened this issue Dec 17, 2020 · 1 comment

Comments

@euZebe
Copy link

euZebe commented Dec 17, 2020

I get the error TS2339: Property 'isValid' does not exist on type 'TextInputMask'. when defining the following component:

import React, { useRef, useState } from "react"
import { TextInputMask } from "react-native-masked-text"
import { DateTime } from "luxon"

interface DateTextFieldProps {
  onChangeDate: (date: Date) => void
}
export const DateTextField = ({ onChangeDate }: DateTextFieldProps) => {
  const [value, setValue] = useState<string>("")
  const ref = useRef<TextInputMask>(null)

  return (
    <TextInputMask
      type={"datetime"}
      options={{
        format: "DD/MM/YYYY",
      }}
      value={value}
      onChangeText={(newValue) => {
        setValue(newValue)
        if (ref.current?.isValid && ref.current?.isValid()) {                     //   <===== Here happens the typescript error
          onChangeDate(DateTime.fromFormat(newValue, "dd/MM/yyyy").toJSDate())
        }
      }}
      keyboardType={"numeric"}
      ref={ref}
    />
  )
}

I can see isValid() in TextInputMaskMethods, but it seems not to be related to

export class TextInputMask extends React.Component<TextInputMaskProps> {}
// TextInputMaskMethods
export class TextInputMaskMethods {
    getElement(): TextInput
    getRawValue(): string
    isValid(): boolean
}

// TextInputMasked
export type TextInputMasked = TextInputMaskMethods | null
@davidwico
Copy link

I was able to fix it like this:

type InputMask = TextInputMask & TextInputMaskMethods
const inputRef = useRef<InputMask>(null)

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

2 participants