github arktypeio/arktype arktype@2.0.4
2.0.4

latest releases: @arktype/util@0.40.0, @ark/util@0.40.0, arktype@2.1.0...
28 days ago

Fix an issue causing global configs to be overwritten when the primary "arktype" entry point is imported:

config.ts

import { configure } from "arktype/config"

configure({ numberAllowsNaN: true })

main.ts

import "./config.ts"
import { type } from "arktype"
// now correctly allows NaN
type.number.allows(Number.NaN)

Previous versions of the docs mistakenly suggested this was possible in a single file. This is not the case in ESM due to hoisting. See the updated global configuration docs here.

Better ParseError when attempting to constraint a morph

Previously, attempting to directly constrain a transformed type was not a type error but gave a confusing error at runtime:

// ParseError: MinLength operand must be a string or an array (was never)
type("string.trim > 2")

We've added a type error and improved the runtime error:

// TypeScript: To constrain the output of string.trim, pipe like myMorph.to('number > 0')
// ParseError: MinLength operand must be a string or an array (was a morph)
type("string.trim > 2")

Fix an issue causing certain complex morph types to not infer output correctly, e.g.:

const types = type.module({
	From: { a: ["1", "=>", () => 2] },
	Morph: ["From", "=>", e => e],
	To: { a: "2" }
})
const U = types.Morph.pipe(e => e, types.To)

// was:
//    (In: never) => To<{ a: 2 }>
// now fixed to:
//    { a: 2 }
const out = U.assert({ a: 1 })

Don't miss a new arktype release

NewReleases is sending notifications on new releases.