Skip to content

about intersect with optional child type idea #1258

@wszgrcy

Description

@wszgrcy
import * as v from 'valibot';
(() => {
  let d = v.intersect([v.object({ a: v.number() }), v.optional(v.object({ b: v.number() }))]);
  console.log();
  type D = v.InferInput<typeof d>;
  type DD =
    | {
        a: number;
      }
    | ({
        a: number;
      } & {
        b: number;
      });

  let d0: D = { a: 1 };
  let d1: DD = { a: 1 };
})();
Image

I know this question was answered before, {}&({}|undefined)=>{}

However, I suddenly came up with the idea yesterday whether it's possible to implement it according to the above DD type. Although this approach might not conform to TypeScript's type system design, it aligns with a person's intuitive sense.

I’m not sure if this design aligns with your vision. If you don't have time to implement it, I can also try to implement it (if feasible)

Metadata

Metadata

Assignees

Labels

feedbackGeneral feedback that does not result in changesquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions