valibot: using `union` as key of `record` adds `undefined` to the value type

import * as v from 'valibot';

const record = v.record(v.union([v.string()]), v.string());

const t: v.Output<typeof record> = { a: undefined }
//    ^ { [x: string]: string | undefined; }
//                              ^ should not be here
const result = v.safeParse(record, t);
console.log(result); // errors correctly

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (12 by maintainers)

Commits related to this issue

Most upvoted comments

The next version of Valibot will allow you to write the following code to solve your problem. Feel free to give me feedback on this in the long run.

import * as v from 'valibot';

const ListSchema = v.picklist(['external', 'online', 'standard', 'telephone']);

const ObjectSchema = v.object(v.entriesFromList(ListSchema.options, v.number()));

Thank you very much for your promptness. Now this also works with numbers and symbols. I’ll try to study the issue. If I have a proposal, I will publish it.

Thank you, I’ll do that 😃