configure({ onUndeclaredKey: 'delete' }) seems to allow extra properties through.

Or have I done something wrong
import { configure, type } from 'arktype'

configure({ onUndeclaredKey: 'delete' })

const Obj = type({ a: 'number' })
const obj = Obj.assert({ a: 1, b: 2 })
console.log(obj)
import { configure, type } from 'arktype'

configure({ onUndeclaredKey: 'delete' })

const Obj = type({ a: 'number' })
const obj = Obj.assert({ a: 1, b: 2 })
console.log(obj)
Yields:
{ a: 1, b: 2 }
{ a: 1, b: 2 }
I'm on 2.0.4
10 Replies
ssalbdivad
ssalbdivad4w ago
The config should be defined in a separate file, see: https://arktype.io/docs/configuration#onundeclaredkey This could have worked in the past though so if that's the case I apologize, it really should never have worked as for other settings fundamentally we have to know the global config ahead of time
AlexWayne
AlexWayneOP4w ago
Ohh okay. Gotcha. That makes sense anyway in a real app. But doesn’t play well with just playing around. And maybe the docs should call that out, as it’s two files in the example but not clear why
ssalbdivad
ssalbdivad4w ago
For most config options you can configure them at a scope level inline, and obviously for onUndeclaredKey you can also use the per-object config. It's just for stuff like onUndeclaredKey that actually changes the properties of the type itself, it gets very messy with caching if you allow it to be configured per scope like that
ssalbdivad
ssalbdivad4w ago
It actually kinda does, just not for each individual item- maybe it should? Feels repetitive but maybe worth
No description
ssalbdivad
ssalbdivad4w ago
I'll add the config comment to the other examples
AlexWayne
AlexWayneOP4w ago
Yeah. Guess I should read the whole thing lol. I was looking here.
No description
AlexWayne
AlexWayneOP4w ago
Sorry posted and ran to lunch so on my phone.
ssalbdivad
ssalbdivad4w ago
You shouldn't have to read all the docs to have context on how to use a particular feature, I'll add it in the other areas as well
AlexWayne
AlexWayneOP4w ago
Thank you for all you do. I’m going to try to replace zod for Arktype at work this year. Wish me luck.
ssalbdivad
ssalbdivad4w ago
Now is the time with docs and 2.0 out! Good luck 🙂

Did you find this page helpful?