Last active
October 4, 2022 03:10
-
-
Save o-henry/b648181298c64e06bf982c2f0a7275e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// schema validation | |
import { z } from "zod" | |
enum Risk { | |
Low, | |
Medium, | |
High, | |
} | |
const _CalculateRiskProfile = (age: _Age): Risk => (__Age.parse(age) < 60 ? Risk.Low : Risk.Medium) | |
const __Age = z.number().refine((age: number) => 0 <= age && age < 120) | |
type _Age = z.infer<typeof __Age> | |
console.log(_CalculateRiskProfile(70)) // 1 | |
console.log(_CalculateRiskProfile(9999)) // Error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment