Comments (16)
@Gnuxie Hi,
I couldn't see anything specifically from #689 that would be causing this, but I could be missing something.
There has been some recent updates made to Composite to further replicate type evaluation in TypeScript (that is to say, TypeBox is trying to compute the intersection of all types passed to Composite such that the output schema / type is an evaluated object
type and not a allOf
representation as would be the case for Intersect). However, the Composite evaluation is an extremely expensive thing to compute, and I think when tagged with ReturnType
inference (instantiation expressions as per your implementation), this is likely pushing out the extents of the type system.
The recent updates for Composite were to do with Union evaluation. You can read about some of the context here #789. I believe these updates went out on 0.32.16, so if you can try 0.32.15 and just let me know if you still see the same issue, I may reinvestigate using the matrix-protection types as a basis for testing.
Workaround
Granted, this could be a misuse of the composite type, and I'm not sure where to go from here
So, much of the issues here would be to do with TypeBox doing deep type evaluation on the Composite types. If it's reasonable to do so, you can swap from Composite to Intersect. The Intersect type should have the same assertion characteristics as Composite, but the schematics are a bit more "extreme" as each Intersect type is expressed via JSON Schema allOf
keyword.
Here's a working version of the matrix-protection types using Intersect instead of Composite.
If you just want to test version 0.32.15 and let me know how that helps solve things, that would be great. I don't know if I'm going to be able to revert Composite back to a previous version (as the current implementation is closer the envisioned computed type), but do think there's potential to further optimize the type for the implementation you've provided. There is some pending work to do with respect to deep type evaluation (of which Composite would be involved), but I don't envision optimizations making it out until TypeBox reaches 0.33.x (which is a fair way off)
For now, give Intersect a try (which will keep you on the latest versions) and just let me know if you still run into issues on 0.32.15, I'll do some digging based on your feedback.
Cheers!
S
from typebox.
Hi, thanks for the speedy response, I'll see what happens in 0.32.15 and report back.
Workaround
For now though, I want to add some context for why I originally moved away from Intersect
, and there are two reasons.
The first is it's less helpful dealing with the typescript union type when trying to debug an issue, since obviously they can become so massive. It can be very difficult to see what is wrong based on the output typescript gives when working with what are believed to be (by me) compatible types. And then VSCode would also expand references to types into a massive type literal when using VSCode's feature to add missing methods when implementing classes in interfaces, and I would get annoyed trying to delete them. Which yes, is probably a silly reason 😓.
e.g.
interface Timeline {
addEvent(event: RoomEvent): void;
}
class StandardTimeline implements Timeline {
addEvent(event: { ... }
& { .... }
& { .... }
) {
throw new TypeError("Unimplemented");
}
}
However, the Composite evaluation is an extremely expensive thing to compute, and I think when tagged with ReturnType inference (instantiation expressions as per your implementation), this is likely pushing out the extents of the type system.
I see, I don't really understand how the type system works but I trust you. I'll follow up shortly
from typebox.
The problem seems to be introduced within 0.32.0
.
from typebox.
Related Issues (20)
- Error when trying to use TSchema as a generic HOT 2
- How to use `Value.Check` with raw json schemas? HOT 4
- Regression bug 0.32.19 HOT 2
- TypeGuard.IsEnum HOT 2
- Better pre-validation errors for invalid TypeBox schema HOT 2
- Static resolution is not working as expected when using a generic function to generate a schema HOT 3
- tsconfig "strict": true - ignore modifiers HOT 2
- `Static` types cannot be used to enforce types from a generic parameter HOT 3
- Applying refinements + general advice on my implementation HOT 11
- Unable to create value of custom class type HOT 2
- Migrate to regexp vs string type in pattern HOT 4
- feedback on Refinement API HOT 2
- Type.Date() cause errors with fastify and querybuilder returning type Date HOT 2
- Should coerce type to array HOT 2
- Interconnected interfaces, missing type annotations and maximum length exceeded. HOT 2
- Add trim option to Type.String() HOT 1
- Should add option to remove redundant prop in Convert() HOT 1
- Metadata missing in custom types HOT 2
- Schema of JSON Schema HOT 3
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.