Releases: arktypeio/arktype
[email protected]
Fix inference for constrained or morphed optional keys (#1040)
const repro = type({
normal: "string>0",
"optional?": "string>0"
})
type Expected = { normal: string; optional?: string }
// these are both now identical to Expected
// (previously, optional was inferred as string.moreThanLength<0>)
type Actual = typeof repro.infer
type ActualIn = typeof repro.infer
[email protected]
Fixed an issue causing morphs on optional keys to give a type error incorrectly indicating they had default values, e.g.:
const t = type({
// previously had a type error here
"optionalKey?": ["string", "=>", x => x.toLowerCase()]
})
// now correctly inferred as
type T = {
optionalKey?: (In: string) => Out<string>
}
@arktype/[email protected]
Patch Changes
- #1028
5fe79c6
Thanks @ssalbdivad! - Bump version
@arktype/[email protected]
Patch Changes
-
#1028
5fe79c6
Thanks @ssalbdivad! - Bump version -
Updated dependencies [
5fe79c6
]:- @arktype/[email protected]
@arktype/[email protected]
Patch Changes
-
#1028
5fe79c6
Thanks @ssalbdivad! - Bump version -
Updated dependencies [
5fe79c6
]:- @arktype/[email protected]
- [email protected]
[email protected]
Improved string default parsing
String defaults are now parsed more efficiently by the core string parser. They can include arbitrary whitespace and give more specific errors.
Fix a resolution issue on certain cyclic unions
// Now resolves correctly
const types = scope({
TypeWithKeywords: "ArraySchema",
Schema: "number|ArraySchema",
ArraySchema: {
"additionalItems?": "Schema"
}
}).export()
[email protected]
String defaults
Previously, setting a default value on an object required a tuple expression:
const myType = type({ value: ["number", "=", 42] })
This is still valid, but now a more convenient syntax is supported for many common cases:
const myType = type({ value: "number = 42" })
The original syntax is still supported, and will be required for cases where the default value is not a serializable primitive e.g.
const mySymbol = Symbol()
const myType = type({ value: ["symbol", "=", mySymbol] })
Chained index access
This allows type-safe chained index access on types via a .get method
const myUnion = type(
{
foo: {
bar: "0"
}
},
"|",
{
foo: {
bar: "1"
}
}
)
// Type<0 | 1>
const fooBar = myUnion.get("foo", "bar")
format
subscope keyword
The new built-in format subscope contains keywords for transforming validated strings:
const foo = " fOO "
const trim = type("format.trim")
// "fOO"
console.log(trim(foo))
const lowercase = type("format.lowercase")
// " foo "
console.log(lowercase(foo))
const uppercase = type("format.uppercase")
// " FOO "
console.log(uppercase(foo))
Many more improvements, especially related to morphs across unions
@arktype/[email protected]
Patch Changes
1bf2066
Thanks @ssalbdivad! - ### Adddict
util for defaultable Records
@arktype/[email protected]
Patch Changes
-
#1024
5284b60
Thanks @ssalbdivad! - ### Add support for index access, less indeterminate morph union errors (see full release notes in ArkType's CHANGELOG) -
Updated dependencies [
1bf2066
]:- @arktype/[email protected]
@arktype/[email protected]
Patch Changes
-
#1024
5284b60
Thanks @ssalbdivad! - ### Add .satisfies as an attest assertion to compare the value to an ArkType definition.attest({ foo: "bar" }).satisfies({ foo: "string" }) // Error: foo must be a number (was string) attest({ foo: "bar" }).satisfies({ foo: "number" })
-
Updated dependencies [
1bf2066
]:- @arktype/[email protected]
- [email protected]