You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a type named Contact which contains an accountNumber. Currently I'm only checking if the account number is within a specified hard-coded range:
interface AccountNumberBrand {
readonly AccountNumber: unique symbol;
}
export const AccountNumber = t.brand(
t.number,
(n): n is t.Branded<number,AccountNumberBrand> =>
n >= 0 && n <= 1000,
'AccountNumber'
);
type AccountNumber = t.TypeOf<typeof AccountNumber>;
//-----------------------------
const Contact = t.type({
AccountNumber: t.union([
withMessage(
AccountNumber,
() => ContactValidationErrorType.InvalidAccountNumber
),
t.undefined,
]),
});
Desired Behavior
I need to extend the validation to check if the account-number exists in the database or not. So I should be able to either pass the list of existing account numbers or a reference to the async function that gets the data from database.
Who does this impact? Who is this for?
Advanced users, typescript users
Describe alternatives you've considered
I can do the this validation in a separate function and have a 2-steps validation, but I prefer not to do it. Because other team members may later forget to use it and miss part of the validation logic.
Your environment
Software
Version(s)
io-ts
2.2.13
TypeScript
4.7.4
The text was updated successfully, but these errors were encountered:
This is out of scope of this library. io-ts is designed to do "pure" validations without side effects. The proposed 2-step validation approach is the one you should go with io-ts.
🚀 Feature request
Current Behavior
I have a type named
Contact
which contains anaccountNumber
. Currently I'm only checking if the account number is within a specified hard-coded range:Desired Behavior
I need to extend the validation to check if the account-number exists in the database or not. So I should be able to either pass the list of existing account numbers or a reference to the async function that gets the data from database.
Who does this impact? Who is this for?
Advanced users, typescript users
Describe alternatives you've considered
I can do the this validation in a separate function and have a 2-steps validation, but I prefer not to do it. Because other team members may later forget to use it and miss part of the validation logic.
Your environment
The text was updated successfully, but these errors were encountered: