ménard
ménard
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
I write tests to check my understanding of programming language and library features all the time
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
Haha
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
Thanks, @Svish
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
it does exactly what I hoped it would
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
const vpm = z
.object({
leader: z.number(),
})
.transform((obj) => ({
...obj,
follower: obj.leader,
}));
it('leader and follower 001', () => {
const ret = vpm.safeParse({ leader: 123 });

expect(ret.success).toBe(true);
expect(ret.data?.leader).toBe(123);
expect(ret.data?.follower).toBe(123);
});
const vpm = z
.object({
leader: z.number(),
})
.transform((obj) => ({
...obj,
follower: obj.leader,
}));
it('leader and follower 001', () => {
const ret = vpm.safeParse({ leader: 123 });

expect(ret.success).toBe(true);
expect(ret.data?.leader).toBe(123);
expect(ret.data?.follower).toBe(123);
});
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
I'll try using .transform like that.
10 replies
ZZod
Created by ménard on 6/12/2024 in #questions
ménard - I'm thinking of something like:typesc...
It's not supposed to be in the input. 🙂
10 replies