LORENS
LORENS
Aarktype
Created by LORENS on 4/17/2025 in #questions
onUndeclaredKey()
I'm encountering a discrepancy between the ArkType playground and my local Express development environment. This type definition works fine on the playground:
const exampleType = type({
code: type("string.trim").to(type("string > 0").describe("Not empty")),
name: type("string.trim").to(type("string > 0").describe("Not empty")),
description: type("string | null").optional(),
}).onUndeclaredKey("reject");
const exampleType = type({
code: type("string.trim").to(type("string > 0").describe("Not empty")),
name: type("string.trim").to(type("string > 0").describe("Not empty")),
description: type("string | null").optional(),
}).onUndeclaredKey("reject");
However, when I use the exact same definition in my project, it throws a ParseError during initialization: ParseError: Intersection at code of string and never results in an unsatisfiable type at throwError (...) at throwParseError (...) ... (rest of stack trace) It seems the .to() chain (type("string.trim").to(type("string > 0")...)) is causing an "unsatisfiable type" error locally. My environment: Node.js: v22.11.0 ArkType: 2.1.18 Project type: Express.js (using TypeScript/tsx) Why might this definition parse correctly on the playground but result in this intersection error in my project? Is there a different way to chain these kinds of refinements (trim then check length > 0) that would avoid this?
3 replies