imMohika
imMohika
Aarktype
Created by imMohika on 3/17/2025 in #questions
undeclared keys in nested object
Hello. I want to use arktype for parsing objects in backend before sending them to client (mainly for removing unwanted keys), But when i use nested object types the undeclared keys won't get deleted ex:
export const tUser = type({
"+": "delete",
phoneNumber: "string",
type: tUserType,
});

export const tAuthMeResult = type({
"requiresOnboarding?": "boolean",
"user?": tUser,
"account?": tAccount,
});
export const tUser = type({
"+": "delete",
phoneNumber: "string",
type: tUserType,
});

export const tAuthMeResult = type({
"requiresOnboarding?": "boolean",
"user?": tUser,
"account?": tAccount,
});
result in
{
"user": {
"id": 2,
"phoneNumber": "XXXX",
"type": "user",
"createdAt": "2025-03-06T12:50:43.849Z",
"updatedAt": "2025-03-06T12:50:43.849Z"
},
{
"user": {
"id": 2,
"phoneNumber": "XXXX",
"type": "user",
"createdAt": "2025-03-06T12:50:43.849Z",
"updatedAt": "2025-03-06T12:50:43.849Z"
},
wanted result:
"user": {
"phoneNumber": "XXXX",
"type": "user"
},
"user": {
"phoneNumber": "XXXX",
"type": "user"
},
Is this a limitation or am i doing something wrong? -# it works correctly if i parse user object with tUser before passing it to tAuthMeResult Thanks for your time
4 replies