Closed collmomo closed 8 months ago
An intersection is the easiest way to achieve this. You can either inline it with a tuple expression:
scope({
base: {name: "string"},
child: ["base", "&", {newProperty: "string"}]
})
Or you could define the additional props separately and intersect them like this:
scope({
base: {name: "string"},
extras: {newProperty: "string"},
child: "base&extras"
})
thanks, I opted for the first choice, just fyi, I'm defining all my api calls within a single scope variable that I exported and I have multiple class entities that are hydrated by those api calls, so im typing these response.data with the infer property by importing and checking for runtime errors.
Great library btw, took me a while to find the one I like, I tried typebox (error message not working), tried suretype, but there was missing features I wanted and some functions were not working (ensure), zod was not for my liking, I wanted runtypes but it's not performing well, and yours checked everything plus eventually performance wise with 2.0 so thanks!
That's great to hear! I'm actually hoping to release a new dev build for 2.0 today. Feel free to join the Discord where I'll post it if you haven't already 🙂
Request a feature
Sorry if this was already asked, i didn't find anything on the issues list. Simply said, having the ability to extend a type definition in the scope section, instead of having to repeat the same variable requirements.
🤷 Motivation
Repeating my variable definitions in the scope definition while I could simply extend an "abstract type"
Why should we prioritize solving it? no need to prioritize, it just aligns with the DRY principle.
💡 Solution
How do you think we should solve the problem?
scope({base:{name:"string"}, {'child<base':{newProperty : "string"}})
Why do you think this is the best solution? it's easy, I'm just not sure on the symbol to use
Did you consider any alternatives? I checked unions and intersections but there's not many documentation on these features