Releases: arktypeio/arktype
[email protected]
Allow overriding builtin keywords
// all references to string in this scope now enforce minLength: 1
const $ = scope({
foo: {
// has minLength: 1
bar: "string"
},
string: schema({ domain: "string" }).constrain("minLength", 1)
})
// has minLength: 1
const s = $.type("string")Fix a ParseError compiling certain morphs with cyclic inputs
Types like the following will now work:
const types = scope({
ArraySchema: {
"items?": "Schema"
},
Schema: "TypeWithKeywords",
TypeWithKeywords: "ArraySchema"
}).export()
const t = types.Schema.pipe(o => JSON.stringify(o))@arktype/[email protected]
Patch Changes
-
#1004
bf85e7dThanks @ssalbdivad! - (see arktype CHANGELOG)Allow overriding builtin keywords
Fix a ParseError compiling certain morphs with cyclic inputs
Rename RegexNode to PatternNode
@arktype/[email protected]
Patch Changes
- #999
21c0105Thanks @ssalbdivad! - Fix chained .describe() on union types (see arktype CHANGELOG)
[email protected]
Fix chained .describe() on union types
// now correctly adds the description to the union and its branches
const t = type("number|string").describe("My custom type")@arktype/[email protected]
Patch Changes
- #997
232fc42Thanks @ssalbdivad! -
@arktype/[email protected]
Patch Changes
-
#997
232fc42Thanks @ssalbdivad! - Add a newparseAsSchemaAPI that acceptsunknownand returns either aParseErroror a Root schema instance with a castable parameter.Useful for stuff like:
const s = schema("number") const fromSerialized = parseAsSchema(s.json)
-
Updated dependencies [
232fc42]:- @arktype/[email protected]
@arktype/[email protected]
Patch Changes
- Updated dependencies [
232fc42]:- @arktype/[email protected]
- [email protected]
[email protected]
Fix autocomplete for private aliases
const $ = scope({
"#kekw": "true",
// now correctly completed as "kekw" without the # prefix,
outerKek: {
kekw: "kek"
}
})[email protected]
Chainable Constraints
Added satisfying, matching, divisibleBy, atLeast, moreThan, atMost, lessThan, atLeastLength, moreThanLength, atMostLength, lessThanLength, atOrAfter, laterThan, atOrBefore, and earlierThan as chainable expressions mirroring existing comparator expressions.
This can be especially convenient for applying constraints to previously defined types like this:
const evenNumber = type("number%2")
const evenNumberLessThan100 = evenNumber.lessThan(100)
const equivalentSingleDeclaration = type("number%2<100")Also works great for chaining off non-string-embedable expressions outside a scope:
const myBoundedArray = type({ foo: "string" })
.array()
.atLeastLength(5)
.atMostLength(20)These chained operations are also typesafe:
// TypeError: Divisor operand must be a number (was a string)
type("string").divisibleBy(2)Cyclic Types Bug Fix
Fixed an issue causing standalone types referencing cyclic types in a scope to crash on JIT-compiled runtime validation.
Types like this will now work correctly:
const $ = scope({
box: {
"box?": "box"
}
})
const box = $.type("box|null")@arktype/[email protected]
Patch Changes
- #995
317f012Thanks @ssalbdivad! - AddleftIfEqualtype utility