Giter VIP home page Giter VIP logo

Comments (2)

sinclairzx81 avatar sinclairzx81 commented on June 21, 2024

@eygsoft Hi! Thanks for reporting!

Yes, this looks like a bug. At this stage, I don't think I'll be able to take a look into the issue until the weekend at the earliest (as I am currently tied up with some other work), however you may be able to workaround this issue if you can reshape the schematics into the following.

const A = Type.Object({
 a: Type.String(),
 b: Type.String()
}, { additionalProperties: false })

const B = Type.Object({
 a: Type.String(),
 c: Type.String()
}, { additionalProperties: false })

const T = Type.Union([A, B]) // T = { a: string, b: string } | { a: string, c: string }

This issue actually crosses over with some other areas of the library where I'm looking to implement a distributive evaluate similar to the following....

TypeScript Link Here

type T = (
  { x: number }
) & (
  { y: number } |
  { z: number }
)

// non-distributive: where passing y | z is observed as unevaluated properties

type A = {[K in keyof T]: T[K]} & {} // type A = { x: number }

// distributive: where y | z are distributed with outer property x

type E<T> = {[K in keyof T]: T[K]} & {}

type B = E<T>                       // type B = { x: number; y: number; } | 
                                    //          { x: number; z: number; }

Note that TypeBox observes the validating schematic as A, where it should be observed as B. The validator should apply distributive union rules to the schematics (which has been challenging at a type level, but may be more tenable at a validation level)

Will keep you posted on any changes here.
Cheers
S

from typebox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.