Comments (9)
@decoursin I agree with your design decision regarding prop?: value
over prop?: value | undefined
, typescript made a mistake in its initial implementation. But adding utils should be done thoughtfully. Effect already has a massive, MASSIVE api surface, which is much more of a factor for possible newcomers from what we see, the effort is in consolidating and reducing.
If you'll go to the original @effect/schema
repo (thats archived) you might find somewhere in its history an api similar to what you're describing. It proved itself to be more confusing with very low ergonomic benefit. Not to me, but I am not the sole consumer of effect.
Theres an assumption in this discussion that exact: true
is always the desired behavior despite being not the default in ts. The more you use schema and start to describe .transform
ations you'll see this can become quite painful unless your api is fully compatible all throughout. Whats more, the decision that this option is cooler than the others is also not based on anything concrete. If anything I would argue that as: "Option"
is the coolest one deserving of its own operator (which it had ( which was consolidated)). This is super subjective..
We can go into more depth about the design and why some things work and look like they are if you really wish, though it would be better done in the discord (you're invited ofc <3)
I gave you a more in-depth answer because I feel that you have the impression that you're not being taken seriously or that we are apathetic to your issue so I wanted to explain that even if very few words are spoken here, theres a lot of history you're not privvy to 😅 . I hope this removes a bit of the bitter taste.. 🙏🏻
This is not to say effect will never have a util that will fulfill your use-case, just that currently theres not enough justification why this needs to be in effect and not in userland
from effect.
No I would definitely say the oppositite that you're giving me way more time on this manner than I deserve 😅. Thanks for your elaboration <3. I wasn't aware that there is some a connection to an original design flaw with ts. I still not sure if that would be make it the right decision but it really doesn't matter what I think, and I clearly don't have a comprehensive understanding of the matter 😅. Thanks so much :)
from effect.
and what about the other options of optional? are they not cool enough to have their own schema constructor? 🤔
.optionalAsOption
, .optionalNullable
, optionalWithDefault
, and then all their intersections... .optionalNullableWithDefault
etc haha
You can probably just make a userland util for this
const optionalExact = <
A,
I,
R,
const Options extends {
readonly default?: never;
readonly as?: never;
readonly nullable?: true;
} | {
readonly default: () => A;
readonly as?: never;
readonly exact?: true;
readonly nullable?: true;
} | {
readonly as: "Option";
readonly default?: never;
readonly nullable?: true;
} | undefined,
>(schema: Schema.Schema<A, I, R>, options?: Options) => Schema.optional(schema, { ...options, exact: true });
from effect.
alternatively, maybe something could be done on the Struct
level like how Partial
and Required
and Mutable
work?
from effect.
Haha I really don't think they are cool enough to have their own constructor. I think option with {exact: true}
is important and will be used a lot, but the others aren't. But that's just my opinion.
from effect.
Personally, I would have said that {exact: true}
should be the default. Because I don't know many APIs sending undefined
, most would send null
instead. But since you already have optional
how it is now, simply adding a new function would be most appropriate IMO.
from effect.
Personally, I would have said that {exact: true} should be the default
You're totally right @decoursin , but we decided that instead of educating everyone to use strict optional we'll be compatible with the common understanding :/
Effect doesn't do global configuration and thats very good, but in this case where you have control over the model all throughout I agree it would be nice.
That said, a Strict
constructor may be just as useful? Strict(Struct({...}))
or as options on Struct
itself? idk, this i hairy, I'm sure gcanti would have a great answer to this
from effect.
A userland util seems to be the simplest and most appropriate solution, moreover defining one's own concept of "optionality" that depends on one's own domain (strict? non strict? including null
?) seems advisable in any case.
from effect.
You guys are free to do whatever you want with your library. However, I don't understand why, if you think I'm right, that you wouldn't change it, or add a second function. I think it's important to lower the boundary as much as possible for newcomers by making the original stuff work as expected. But this is just my opinion. I'm not complaining, I'm thankful for your project.
from effect.
Related Issues (20)
- From Discord: Memory Leak in Effect: `zipLatest` with `async` Stream Causing Fiber Overflow HOT 1
- Add a drizzle-schema package HOT 5
- Idea: Schema variants HOT 3
- Weblock support in browser platform package HOT 1
- From Discord: Is Option.firstSomeOf expected to work with an array of Data.taggedEnum<AlgebraicDataType?
- Schema.TaggedError doesn't have nicely formatted cause when logged to console (unlike Data.TaggedError)
- Add new Order.localeString ordering option
- Predicate.or should handle refinements as Predicate.and does
- Logged errors only show the first child cause instead of displaying error causes recursively
- RPC File support
- From Discord: Confusion Over Multiple Documentation Versions for Effect-TS API
- From Discord: Schema base64 string -> utf8 string -> json parse
- Suggestion: improve DX of type errors from inside `pipe` and `flow`
- From Discord: Accumulating Incomplete JSON Chunks from a ReadableStream
- Enhance sum type workflow (Data.taggedEnum)
- Cause.UnknownException causes exception when using Bun
- JSONSchema.make does not have same behaviour as JSONSchema.to => erasing properties & not working for some Schema types HOT 1
- Effect.Tag with non Effect-returning functions
- From Discord: TypeScript Type Incompatibility Issue with Generic Schema and Optional Values
- Move type helpers from nested namespace to the top-level namespace HOT 1
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 effect.