picklemik
picklemik
Aarktype
Created by picklemik on 5/3/2025 in #questions
Can't infer type of schema when using "scope"
I am using arktype to parse data from incoming web requests. I define the schema and the parsed result will be passed into my handler. It looks like this and is working perfectly fine right now:
server.endpoint({
url: "PUT /admin/user/:id",
auth: "basic",
params: type({
id: "string",
}),
query: type({
"year?": "string.integer.parse",
}),
form: type({
firstName: "string",
lastName: "string",
code: "string",
})
async handler(req, reply) {
// req.params has the infered type from the schema, e.g. { id: string }
}
server.endpoint({
url: "PUT /admin/user/:id",
auth: "basic",
params: type({
id: "string",
}),
query: type({
"year?": "string.integer.parse",
}),
form: type({
firstName: "string",
lastName: "string",
code: "string",
})
async handler(req, reply) {
// req.params has the infered type from the schema, e.g. { id: string }
}
What I want to do now is change id in the params schema to not be a string, but instead define my own "objectId" value. It would parse the string into a mongo ObjectId object, so I don't have to do that in the handler. I believe scopes are what I am looking for, so I tried doing that, but it breaks my type system and I don't understand why. I recreated the issue I have in this playground: https://tinyurl.com/arktype
18 replies