A
arktype•3w ago
Tom

Can arktype drop data not covered by schema?

I want to regurgitate my input according to the schema model, e.g:
const user = type({
name: "string",
})

const out = user({name: "bob", age: 51})
const user = type({
name: "string",
})

const out = user({name: "bob", age: 51})
I'd want to make out contain only {name: "bob"}. Is there a way to do this with arktype?
3 Replies
Dimava
Dimava•3w ago
https://arktype.io/docs/objects#properties-undeclared @ArkDavid rejoice, it's my first completely doc answer!
const user = type({
name: "string",
'+': 'delete', // or 'reject'
})

const out = user({name: "bob", age: 51})
const user = type({
name: "string",
'+': 'delete', // or 'reject'
})

const out = user({name: "bob", age: 51})
Tom
TomOP•3w ago
ooh, thanks! I'll have a play with that so I mostly want to do this for a test; I want to load in some example data, have it return everything it was sensitive to, and check that it matches the input in certain cases. Is there a runtime way of enabling this? actually, thinking about it, I think I always want "+": "delete",, this is already the behaviour of the equivalent pydantic models so that's fine
ssalbdivad
ssalbdivad•3w ago
You saw in that case there's a global config right? First of many 📚

Did you find this page helpful?