关键词

TypeScript

所有*内置 TypeScript 关键词都可直接使用。
const  = ({
	string: "string",
	date: "Date"
})

* anyvoid 对于运行时验证具有误导性且不必要,因此默认不作为关键词包含。

子类型

子类型关键词会细化或转换其根类型。

const  = ({
	dateFormattedString: "string.date",
	transformStringToDate: "string.date.parse",
	isoFormattedString: "string.date.iso",
	transformIsoFormattedStringToDate: "string.date.iso.parse"
})

您可以通过部分定义(如 "string.")轻松使用自动完成功能探索可用的子类型。

所有关键词

此表格包含默认 type API 中所有可用的关键词。要定义您自己的可嵌入字符串关键词,请参阅作用域

string

AliasDescription
stringa string
string.alphaonly letters
string.alphanumericonly letters and digits 0-9
string.base64base64-encoded
string.base64.urlbase64url-encoded
string.capitalizea morph from a string to capitalized
string.capitalize.preformattedcapitalized
string.creditCarda credit card number and a credit card number
string.datea string and a parsable date
string.date.epochan integer string representing a safe Unix timestamp
string.date.epoch.parsea morph from an integer string representing a safe Unix timestamp to a Date
string.date.isoan ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date
string.date.iso.parsea morph from an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date to a Date
string.date.parsea morph from a string and a parsable date to a Date
string.digitsonly digits 0-9
string.emailan email address
string.hexhex characters only
string.integera well-formed integer string
string.integer.parsea morph from a well-formed integer string to an integer
string.ipan IP address
string.ip.v4an IPv4 address
string.ip.v6an IPv6 address
string.jsona JSON string
string.json.parsesafe JSON string parser
string.lowera morph from a string to only lowercase letters
string.lower.preformattedonly lowercase letters
string.normalizea morph from a string to NFC-normalized unicode
string.normalize.NFCa morph from a string to NFC-normalized unicode
string.normalize.NFC.preformattedNFC-normalized unicode
string.normalize.NFDa morph from a string to NFD-normalized unicode
string.normalize.NFD.preformattedNFD-normalized unicode
string.normalize.NFKCa morph from a string to NFKC-normalized unicode
string.normalize.NFKC.preformattedNFKC-normalized unicode
string.normalize.NFKDa morph from a string to NFKD-normalized unicode
string.normalize.NFKD.preformattedNFKD-normalized unicode
string.numerica well-formed numeric string
string.numeric.parsea morph from a well-formed numeric string to a number
string.regexa string and a regex pattern
string.semvera semantic version (see https://semver.org/)
string.trima morph from a string to trimmed
string.trim.preformattedtrimmed
string.uppera morph from a string to only uppercase letters
string.upper.preformattedonly uppercase letters
string.urla string and a URL string
string.url.parsea morph from a string and a URL string to a URL instance
string.uuida UUID
string.uuid.v1a UUIDv1
string.uuid.v2a UUIDv2
string.uuid.v3a UUIDv3
string.uuid.v4a UUIDv4
string.uuid.v5a UUIDv5
string.uuid.v6a UUIDv6
string.uuid.v7a UUIDv7
string.uuid.v8a UUIDv8

number

AliasDescription
numbera number
number.InfinityInfinity
number.NaNNaN
number.NegativeInfinity-Infinity
number.epochan integer representing a safe Unix timestamp
number.integeran integer
number.safeat least -9007199254740991 and at most 9007199254740991

other

AliasDescription
Keya string or a symbol
biginta bigint
booleanboolean
falsefalse
nevernever
nullnull
symbola symbol
truetrue
undefinedundefined
unknownunknown
unknown.anyunknown

object

AliasDescription
objectan object
object.json{ [string]: $jsonObject, a number, a string, false, null or true }
object.json.stringifya morph from { [string]: $jsonObject, a number, a string, false, null or true } to a string

array

AliasDescription
Arrayan array
Array.indexmatched by ^(?:0|[1-9]\d*)$
Array.liftFroma generic type for Function
Array.readonlyan array
ArrayBufferan ArrayBuffer instance

FormData

AliasDescription
FormDataa FormData instance
FormData.parsea morph from a FormData instance to an object representing parsed form data
FormData.parsedan object representing parsed form data
FormData.valuea string or a File instance

TypedArray

AliasDescription
TypedArray.BigInt64a BigInt64Array
TypedArray.BigUint64a BigUint64Array
TypedArray.Float32a Float32Array
TypedArray.Float64a Float64Array
TypedArray.Int16an Int16Array
TypedArray.Int32an Int32Array
TypedArray.Int8an Int8Array
TypedArray.Uint16a Uint16Array
TypedArray.Uint32a Uint32Array
TypedArray.Uint8a Uint8Array
TypedArray.Uint8Clampeda Uint8ClampedArray

instanceof

AliasDescription
Bloba Blob instance
Datea Date
Erroran Error
Filea File instance
Functiona function
Headersa Headers instance
Mapa Map
Promisea Promise
RegExpa RegExp
Requesta Request instance
Responsea Response instance
Seta Set
URLa URL instance
WeakMapa WeakMap
WeakSeta WeakSet

generic

AliasDescription
Excludeexclude branches of a union like Exclude("boolean", "true")
Extractextract branches of a union like Extract("0 | false | 1", "number")
Mergemerge an object's properties onto another like Merge(User, { isAdmin: "true" })
Omitomit a set of properties from an object like Omit(User, "age")
Partialmake all named properties of an object optional like Partial(User)
Pickpick a set of properties from an object like Pick(User, "name | age")
Recordinstantiate an object from an index signature and corresponding value type like Record("string", "number")
Requiredmake all named properties of an object required like Required(User)

On this page