import { type } from "arktype"
// I have some class that validates or throws. I want to parse an instance of that from a config file.
class ValidatedUserID {
static fromString(value: string): ValidatedUserID {
return new ValidatedUserID(value)
}
private constructor(readonly data: string) {}
}
const UserID = type("string")
.describe("a userID")
.pipe.try(
ValidatedUserID.fromString
)
.describe("No, really, this is a user ID")
const User = type({
id: UserID
})
const user = User.assert({
iD: "typo, oops"
})
import { type } from "arktype"
// I have some class that validates or throws. I want to parse an instance of that from a config file.
class ValidatedUserID {
static fromString(value: string): ValidatedUserID {
return new ValidatedUserID(value)
}
private constructor(readonly data: string) {}
}
const UserID = type("string")
.describe("a userID")
.pipe.try(
ValidatedUserID.fromString
)
.describe("No, really, this is a user ID")
const User = type({
id: UserID
})
const user = User.assert({
iD: "typo, oops"
})