Skip to content

Releases: arktypeio/arktype

@arktype/[email protected]

24 Jun 22:18
90fe9bf
Compare
Choose a tag to compare

Patch Changes

[email protected]

24 Jun 22:18
90fe9bf
Compare
Choose a tag to compare
[email protected] Pre-release
Pre-release

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]

23 Jun 01:15
c5569dd
Compare
Choose a tag to compare

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]

23 Jun 01:15
c5569dd
Compare
Choose a tag to compare

Patch Changes

@arktype/[email protected]

23 Jun 01:15
c5569dd
Compare
Choose a tag to compare

Patch Changes

@arktype/[email protected]

23 Jun 01:14
c5569dd
Compare
Choose a tag to compare

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]:

[email protected]

13 Jun 23:50
1aa6064
Compare
Choose a tag to compare

Fix constrained narrow/pipe tuple expression input inference

Previously constraints were not stripped when inferring function inputs for tuple expressions like the following:

// previously errored due to data being inferred as `number.moreThan<0>`
// now correctly inferred as number
const t = type(["number>0", "=>", data => data + 1])

Fix a bug where paths including optional keys could be included as candidates for discrimination (see #960)

Throw descriptive parse errors on unordered unions between indiscriminable morphs and other indeterminate type operations (see #967)

@arktype/[email protected]

13 Jun 23:50
1aa6064
Compare
Choose a tag to compare

Patch Changes

@arktype/[email protected]

13 Jun 23:50
1aa6064
Compare
Choose a tag to compare

Patch Changes

@arktype/[email protected]

13 Jun 23:50
1aa6064
Compare
Choose a tag to compare

Minor Changes

  • #1011 2be4f5b Thanks @ssalbdivad! - ### Throw by default when attest.instantiations() exceeds the specified benchPercentThreshold

    Tests like this will now correctly throw inline instead of return a non-zero exit code:

    it("can snap instantiations", () => {
    	type Z = makeComplexType<"asbsdfsaodisfhsda">
    	// will throw here as the actual number of instantiations is more
    	// than 20% higher than the snapshotted value
    	attest.instantiations([1, "instantiations"])
    })

    Snapshotted completions will now be alphabetized

    This will help improve stability, especially for large completion lists like this one which we updated more times than we'd care to admit 😅

    attest(() => type([""])).completions({
    	"": [
    		"...",
    		"===",
    		"Array",
    		"Date",
    		"Error",
    		"Function",
    		"Map",
    		"Promise",
    		"Record",
    		"RegExp",
    		"Set",
    		"WeakMap",
    		"WeakSet",
    		"alpha",
    		"alphanumeric",
    		"any",
    		"bigint",
    		"boolean",
    		"creditCard",
    		"digits",
    		"email",
    		"false",
    		"format",
    		"instanceof",
    		"integer",
    		"ip",
    		"keyof",
    		"lowercase",
    		"never",
    		"null",
    		"number",
    		"object",
    		"parse",
    		"semver",
    		"string",
    		"symbol",
    		"this",
    		"true",
    		"undefined",
    		"unknown",
    		"uppercase",
    		"url",
    		"uuid",
    		"void"
    	]
    })

Patch Changes