arktype
arktype copied to clipboard
Narrow expressions not executed when type is spread
Report a bug
🔎 Search Terms
narrow expressions spread operator scope
🧩 Context
System: OS: Linux 6.8 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish) CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz Memory: 9.03 GB / 23.23 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 22.5.1 - ~/.nvm/versions/node/v22.5.1/bin/node npm: 10.8.2 - ~/.nvm/versions/node/v22.5.1/bin/npm npmPackages: @ark/schema: 0.46.0 @ark/util: 0.46.0 arktype: ^2.1.20 => 2.1.20 typescript: ~5.6.2 => 5.6.3
🧑💻 Repro
import {type, scope} from "arktype";
const registrationScope = scope({
"#passwordWithConfirmation": () => registrationScope.type({
password: type("string>7"),
confirmPassword: type("string")
}).narrow((value, ctx) => {
if (value.password !== value.confirmPassword) {
return ctx.reject({
expected: "identical to password",
actual: "",
path: ["confirmPassword"]
});
}
return true;
}),
fullSchema: () => registrationScope.type({
"...": "passwordWithConfirmation",
email: "string",
firstName: "string",
lastName: "string",
})
})
const Thing = registrationScope.export().fullSchema;
const out = Thing({
email: "",
firstName: "",
lastName: "",
password: "abc11111111D",
confirmPassword: "abc"
})
A workaround is to set the narrow expression directly on fullSchema, but that means passwordWithConfirmation can't really be reused