A
arktype2mo ago
GreggOD

How can "string" type be not empty?

Without having to add ">0" to all my string types is there an easy way to ensure that type of "string" cannot be empty string?
type({
name: "string", // expect to be a value and not ""
city: "string", // expect to be a value and not ""
"town?": "string", // expect to be "" or undefined
})
type({
name: "string", // expect to be a value and not ""
city: "string", // expect to be a value and not ""
"town?": "string", // expect to be "" or undefined
})
Thanks
2 Replies
LukeAbby
LukeAbby2mo ago
@GreggOD Well you can make a helper type:
import { type } from "arktype";

const nonEmptyString = type("string>0")

type({
name: nonEmptyString,
city: nonEmptyString,
"town?": nonEmptyString,
})
import { type } from "arktype";

const nonEmptyString = type("string>0")

type({
name: nonEmptyString,
city: nonEmptyString,
"town?": nonEmptyString,
})
beyond that I don't know if there's any "global config" to make it so that non-empty strings are disallowed I doubt there is
GreggOD
GreggODOP5w ago
Thats what we were thinking, thanks for confirming

Did you find this page helpful?