Comments (2)
@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....
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)
- transform object property encoding HOT 4
- Built-in types for JSON? HOT 1
- MaxLength on keys defining a Type.Record HOT 2
- decode object with null prototype HOT 3
- Validate Enum at a low level HOT 4
- AOT compilation using custom registered types HOT 2
- Uses of BigInt over the project breaks compatibility w/ ES5 (?) HOT 3
- Typescript doesn't suggests the props using Pick or Omit HOT 1
- UUID not accpeted as string HOT 2
- How to import just Decode? HOT 4
- How to check if a schema conforms? HOT 2
- email validation doesn't work? HOT 2
- `Value.Cast` casts to wrong schema when called with union of `Refs` HOT 1
- Support for `definitions`? HOT 1
- Cannot reference a recursive type HOT 7
- Cannot use .map() inside Union with Literal HOT 2
- Nested `Type.Intersect` Errors
- Incorrect inferred type for the empty object `Type.Object({})`. HOT 3
- Types for both CJS and ESM cause ambiguity and prevent correct type resolution. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typebox.