Open
Description
Description
Hi,
I dearly want to report this issue about seemingly wrong typings in @IsMobilePhone()
.
Your documentation states (Tag: 0.14.2):
(locale is either an array of locales (e.g ['sk-SK', 'sr-RS'])
But one can't pass an array, only a string value
While looking at: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/372a2368108145e266bab7dc18ffff3806d10ee7/types/validator/index.d.ts#L1064
Validator library does accept an array of locales.
Minimal code-snippet showcasing the problem
Does not accept array type (pre-compile time):
class ContactInfo {
@IsOptional()
@IsMobilePhone(['nl-NL'])
mobilePhone?: string
}
Does accept hacky type (but types are not aligned):
class ContactInfo {
@IsOptional()
@IsMobilePhone(['nl-NL'] as unknown as MobilePhoneLocale)
mobilePhone?: string
}
Expected behavior
class-validator decorator @IsMobilePhone()
should ensure this also accepts an array.
And ensure it is tested by the unit tests.
For example:
locale?: ValidatorJS.MobilePhoneLocale | Array<ValidatorJS.MobilePhoneLocale>
Actual behavior
- Typing suggests it only accepts a
string
shows pre compile time error:Argument of type 'string[]' is not assignable to parameter of type 'MobilePhoneLocale | undefined'.
Kind regards.