`.and` with default, expected behavior?

import { type } from "arktype";

const a = type({
someVal: type('string > 0')
});

const b = a.and({
someVal: type('"foo"').default('foo')
});

console.log(b.from({}));
import { type } from "arktype";

const a = type({
someVal: type('string > 0')
});

const b = a.and({
someVal: type('"foo"').default('foo')
});

console.log(b.from({}));
This fails with error: Uncaught (in promise) AggregateError: someVal must be "foo" (was missing) Is this expected? In rc 26 this worked - just upgraded to 30 and it does not.
2 Replies
Jeffrey Konowitch
Using .merge fixed this FYI
import { type } from "arktype";

const a = type({
someVal: type('string > 0')
});

const b = a.merge({
someVal: type('"foo"').default('foo')
});

console.log(b.from({}));
import { type } from "arktype";

const a = type({
someVal: type('string > 0')
});

const b = a.merge({
someVal: type('"foo"').default('foo')
});

console.log(b.from({}));
ssalbdivad
ssalbdivad3w ago
Hmm yeah I'd say the newer version is accurate because you shouldn't really be able to intersect an optional or defaultable prop with a required prop and get anything other than a required prop But I can see how that could be tricky. merge is usually the way to go for combining properties anyways

Did you find this page helpful?