aabad_ankit
aabad_ankit
Aarktype
Created by SynthLuvr on 6/12/2024 in #questions
Can you create types with dynamic literals?
Thank You. This is what I was looking for.
44 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
using "arktype": "^2.0.0-rc.5",
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
No description
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Great, I will give this a try
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Are you saying that using map it is possible to remove all the default from all the properties(nested or otherwise) (I dont' know the properties name which can have default)
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Just a test example so I do need to validate a complete object without applying default values so .withoutOptionalAndDefaultMeta should solve my problem.
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Any way to circumvent default values
const test = type({
name: b,
info: { email: "string.email & string.lower", age: "number=10" }
});
console.log(test.get("info")({email: "[email protected]"}));
const test = type({
name: b,
info: { email: "string.email & string.lower", age: "number=10" }
});
console.log(test.get("info")({email: "[email protected]"}));
Gives me { email: '[email protected]', age: 10 } dont want it to add age to it
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Thank you so much for the quick response
25 replies
Aarktype
Created by aabad_ankit on 10/3/2024 in #questions
Partial Application of the validator
Awesome. For my current use case get should be sufficient.
25 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
Thank you so much for all the help
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
@ArkDavid You were suggesting to use narrow, can I do it on union and solve my problem
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
a code sample will be super useful
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
but delete on undeclared key will work on union right once you have built in discrimination based on key presence
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
const nameArk = type({ name: "string", age: "number" }).onDeepUndeclaredKey(
"delete"
);
const cityArk = type({ city: "string" }).onDeepUndeclaredKey("delete");
const input = { name: "ark" };
const result = nameArk.or(cityArk)(input)
console.log(result.summary)
const nameArk = type({ name: "string", age: "number" }).onDeepUndeclaredKey(
"delete"
);
const cityArk = type({ city: "string" }).onDeepUndeclaredKey("delete");
const input = { name: "ark" };
const result = nameArk.or(cityArk)(input)
console.log(result.summary)
This prints age must be a number (was missing) or city must be a string (was missing). I just want the error msg to be age must be a number (was missing) to do that I am currently doing something like this
const vm = {
"name": nameArk,
"city": cityArk
};
const input = { name: "ark" };
let result: typeof nameArk.infer | typeof cityArk.infer;
for (const key of keys(vm)) {
if (key in input) {
result = vm[key].assert(input);
break;
}
}
const vm = {
"name": nameArk,
"city": cityArk
};
const input = { name: "ark" };
let result: typeof nameArk.infer | typeof cityArk.infer;
for (const key of keys(vm)) {
if (key in input) {
result = vm[key].assert(input);
break;
}
}
so I wanted to know if there is more idiomatic way to do this
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
@ArkDavid @Dimava the Monoreaper What will be the most idiomatic way to do the validation for such union types to get correct error msg. Do I need to check for the properties and do validation by creating a validator map
import { type } from "arktype";
import { keys } from "remeda";

const nameArk = type({ name: "string" }).onDeepUndeclaredKey("delete");
const cityArk = type({ city: "string" }).onDeepUndeclaredKey("delete");
const vm = {
"name": nameArk,
"city": cityArk
};
const input = { name: "ark" };
let result: typeof nameArk.infer | typeof cityArk.infer;
for (const key of keys(vm)) {
if (key in input) {
result = vm[key].assert(input);
break;
}
}

// peform pipe operation here
import { type } from "arktype";
import { keys } from "remeda";

const nameArk = type({ name: "string" }).onDeepUndeclaredKey("delete");
const cityArk = type({ city: "string" }).onDeepUndeclaredKey("delete");
const vm = {
"name": nameArk,
"city": cityArk
};
const input = { name: "ark" };
let result: typeof nameArk.infer | typeof cityArk.infer;
for (const key of keys(vm)) {
if (key in input) {
result = vm[key].assert(input);
break;
}
}

// peform pipe operation here
This is getting verbose. I am giving example of just one field but my inputs are larger and I have 5 different types of input. If I could have done union then I would have declared on deepUndeclaredkey("delete") on just the union as well as the pipe on the union
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
Oh Yeah, Understood 👍
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
I am getting name must be a string (was missing) or city must be a string (was missing) for both the code snippets below.
const type1 = type({"name": "string",age:"number","+": "delete"})
const type2 = type({"city": "string","+": "delete"})
const union = type([type1,"|",type2])
const result = union({"age":12})
console.log(result.summary)
const type1 = type({"name": "string",age:"number","+": "delete"})
const type2 = type({"city": "string","+": "delete"})
const union = type([type1,"|",type2])
const result = union({"age":12})
console.log(result.summary)
and
const type1 = type({ name: "string", age: "number", "+": "delete" }).pipe(
(o) => {
return { ...o, kind: "person" as const };
}
);
const type2 = type({ city: "string", "+": "delete" }).pipe((o) => {
return { ...o, kind: "city" as const };
});

const union = type([type1, "|", type2]);
const result = union({ age: 12, kind: "city" });
console.log(result.summary);
const type1 = type({ name: "string", age: "number", "+": "delete" }).pipe(
(o) => {
return { ...o, kind: "person" as const };
}
);
const type2 = type({ city: "string", "+": "delete" }).pipe((o) => {
return { ...o, kind: "city" as const };
});

const union = type([type1, "|", type2]);
const result = union({ age: 12, kind: "city" });
console.log(result.summary);
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
@ArkDavid How can I get better error msg for this
const type1 = type({"name": "string",age:"number"})
const type2 = type({"city": "string"})

const union = type([type1,"|",type2])
const result = union({"age":12})
console.log(result.summary)
const type1 = type({"name": "string",age:"number"})
const type2 = type({"city": "string"})

const union = type([type1,"|",type2])
const result = union({"age":12})
console.log(result.summary)
prints "name must be a string (was missing) or city must be a string (was missing)" since age is already there shouldn't it just say "name must be a string (was missing) "
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
docs will certainly help.
66 replies
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Can I add a default value to a type if everything other satisfies in a union type
I need to learn a lot 🙂 . This library is just awesome.
66 replies