github arktypeio/arktype arktype@3.0.1

41 minutes ago

Infer t from a Type passed to a generic function

A function generic over the Type it's passed, like <t>(T: Type<t>) => t, inferred t wrong in 3.0.0 for most object Types: the return types of selective .partial(...keys) and .required(...keys) let it infer every key as optional, and Date, Map or a class instance as an object of their methods:

const unwrap = <t>(T: Type<t>): t => T.t

// was: { type?: "varchar"; class?: "data_type" }
// now: { type: "varchar"; class: "data_type" }
unwrap(type({ type: "'varchar'", class: "'data_type'" }))

// was: { toString: () => string; toDateString: () => string; ... }
// now: Date
unwrap(type("Date"))

It also preserves brands, which every version so far dropped, and infers an object piped through a function, which previously inferred as unknown:

// was: string
// now: Brand<string, "id">
unwrap(type("string#id"))

// was: unknown
// now: (In: { a: string }) => Out<number>
unwrap(type({ a: "string" }).pipe(o => o.a.length))

Full changelog: https://github.com/arktypeio/arktype/blob/arktype@3.0.1/ark/type/CHANGELOG.md

Don't miss a new arktype release

NewReleases is sending notifications on new releases.