aabad_ankit
aabad_ankit
Aarktype
Created by aabad_ankit on 9/4/2024 in #questions
Is there a way to rename the key in parse result
const t = type({name:"string"}) const result = t({name:"ankit"}) i want the result to be {alias:"ankit"} how can i replace the key "name" with "alias"
3 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 type1 = type({name: "string"}) const type2 = type({city: "string"}) const union = type1.or(type2) const result1 = union({name:"ankit"}) const result2 = union({city:"Ajmer"}) I want result1 to be {name: "ankit",kind:"name"} I want result2 to be {city:"Ajmer",kind:"city"} or better const [kind,result] = union({name:"ankit"}) here kind will be "name" and result will be {name:"ankit"} and kind type will be "name"| "city" can I add these default value of kind in the type definitions so that if parsed with that validator from the union the kind is added
66 replies