github arktypeio/arktype arktype@2.0.0-dev.25

latest releases: @arktype/util@0.44.1, @ark/util@0.44.1, @ark/type@2.1.6...
9 months ago

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

Don't miss a new arktype release

NewReleases is sending notifications on new releases.