Skip to content

Instantly share code, notes, and snippets.

@omerlh
Last active July 23, 2021 07:42
Show Gist options
  • Save omerlh/504c0050736df8a600a67b5f56641c2d to your computer and use it in GitHub Desktop.
Save omerlh/504c0050736df8a600a67b5f56641c2d to your computer and use it in GitHub Desktop.
Refined Types
interface UserInput {
age: Number
}
var input = JSON.parse("{\"age\": \"hello\"}") as UserInput
console.log(typeof(input.age))
import eu.timepit.refined.api.{Refined}
import eu.timepit.refined.boolean._
import eu.timepit.refined.string._
object Types {
type userEmail = String Refined MatchesRegex[".*@gmail.com"]
type ipAddress = String Refined IPv4 Or IPv6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment