I have the following phone number validation using yup but I am getting TS error after upgrading
"yup": ^0.27.0 to "yup": "^0.29.3"
and
"@types/yup": "^0.26.27" to "@types/yup": "^0.29.7"
const ValidationSchema = Yup.object().shape<ICreateUserForm>({
phone: Yup.string()
.required("Required")
.test("countryCode", "Must include country code", (phone?: string) => {
return !!phone && phone.startsWith("+")
})
.test("isValidNumber", "Must be valid phonenumber", (phone?: string) => {
const parsedNumber = !!phone && parsePhoneNumberFromString(phone)
return parsedNumber && parsedNumber.isValid() ? true : false
})
})
Error
No overload matches this call.
Overload 1 of 4, '(name: string, message: TestOptionsMessage<{}, any>, test: TestFunction<string | null | undefined, object>): StringSchema<string, object>', gave the following error.
Argument of type '(phone?: string | undefined) => boolean' is not assignable to parameter of type 'TestFunction<string | null | undefined, object>'.
Types of parameters 'phone' and 'value' are incompatible.
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
Overload 2 of 4, '(name: string, message: TestOptionsMessage<{}, any>, test: AssertingTestFunction<string, object>): StringSchema<string, object>', gave the following error.
Argument of type '(phone?: string | undefined) => boolean' is not assignable to parameter of type 'AssertingTestFunction<string, object>'.
Signature '(phone?: string | undefined): boolean' must be a type predicate. TS2769
Following is the Type definition of phone
type AvailableLanguage = "fi" | "en"
export interface CreateUserForm {
firstName: string
lastName: string
email: string
phone: string
language: AvailableLanguage
}
Since there are bo breaking changes in the recent changelog. I am not sure what has happened behind the scenes
https://github.com/jquense/yup/blob/master/CHANGELOG.md https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yup