`.out` is inferring `unknown`

import { ArkErrors, type } from "arktype";

const ToBigInt = type("string").pipe((v) => BigInt(v));

const MyType = type({
a: ToBigInt,
b: "number"
});

// type MyType = typeof MyType.out;
// Results in:
// type MyType = Type<{
// a: unknown;
// b: number;
// }, {}>


type MyType = Exclude<ReturnType<typeof MyType>, ArkErrors>;
// Is correct:
// type MyType = {
// a: bigint;
// b: number;
// }
import { ArkErrors, type } from "arktype";

const ToBigInt = type("string").pipe((v) => BigInt(v));

const MyType = type({
a: ToBigInt,
b: "number"
});

// type MyType = typeof MyType.out;
// Results in:
// type MyType = Type<{
// a: unknown;
// b: number;
// }, {}>


type MyType = Exclude<ReturnType<typeof MyType>, ArkErrors>;
// Is correct:
// type MyType = {
// a: bigint;
// b: number;
// }
2 Replies
SynthLuvr
SynthLuvrOP4d ago
hmm, seems it has changed to .inferOut, which works fine .out.infer does not work, which I thought it used to work like this
ssalbdivad
ssalbdivad3d ago
out being inferred as unknown is actually more precise. If you want to infer the output of the current Type, you should use .infer or .inferOut. .out has always been a way to extract a new type representing the output of your type with morphs extracted. If your type includes morphs without output validation though, we can't do anything better than unknown at runtime. Previously, we'd give the narrowed type from TS but at runtime it would just be lying because there is no way to know your pipe returns a bigint

Did you find this page helpful?