all InfoSec news
Zod - TypeScript-first schema declaration and validation library #8
Dec. 13, 2023, 3 p.m. | Nhan Nguyen
DEV Community dev.to
✨ Be Specific with Allowed Types ✨
We will validate forms again in this example.
const Form = z.object({
repoName: z.string(),
privacyLevel: z.string(),
})
export const validateFormInput = (values: unknown) => {
const parsedData = Form.parse(values);
return parsedData;
}
This time Form has a privacyLevel that can be two types: either private or public:
const Form = z.object({
repoName: z.string(),
privacyLevel: z.string(),
});
If we were going to represent this in TypeScript, we would write:
type PrivacyLevel = 'private' …
declaration export forms javascript library object programming return types typescript validation
More from dev.to / DEV Community
Jobs in InfoSec / Cybersecurity
CyberSOC Technical Lead
@ Integrity360 | Sandyford, Dublin, Ireland
Cyber Security Strategy Consultant
@ Capco | New York City
Cyber Security Senior Consultant
@ Capco | Chicago, IL
Sr. Product Manager
@ MixMode | Remote, US
Security Compliance Strategist
@ Grab | Petaling Jaya, Malaysia
Cloud Security Architect, Lead
@ Booz Allen Hamilton | USA, VA, McLean (1500 Tysons McLean Dr)