-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING: convert @obj and @deriving(abstract) to use optional record fields #154
Conversation
5223539
to
3d0b221
Compare
@jeddeloh There are more fields that are typed as i.e. QueryResult, MutationResult, etc. let result = Query.use()
switch result {
| {data: {me: {todos}}, _} => Array.joinWith(todos, ", ")
| {data: ?None, _} => "<nothing here>"
} This feels a bit strange to type I think, but curious as to your thoughts on the matter. There's also the possibility of the field being present vs being explicitly undefined--which seems to be handled the same way today by the compiler but I don't think there's any guarantee of that saying the same. |
|
FYI I checked this out and I didn't have to make any code changes in a consuming application, so while technically breaking it shouldn't be disruptive to anyone.
Ah I should've used an example that was actually applicable--https://github.com/apollographql/apollo-client/blob/main/src/core/types.ts#L142
|
Yeah, that typescript for |
I was telling a coworker about this distinction with present-and-undefined vs not-present and when we checked the ReScript output, I found the check does not actually seem to make the distinction--so maybe it is moot, though it seems potentially unsafe with values created from javascript. type t<'data> = { data: 'data, error?: Error.t }
type example = { foo: string, bar: int }
let myData = { data: { foo: "baz", bar: 1 } }
let log = (data) => switch data {
| {error} => Console.log("there was an error")
| {data} => Console.log("hi data")
} // Generated by ReScript, PLEASE EDIT WITH CARE
function log(data) {
if (data.error !== undefined) {
console.log("there was an error");
} else {
console.log("hi data");
}
}
var myData = {
data: {
foo: "baz",
bar: 1
}
};
export {
myData ,
log ,
}
/* No side effect */ |
3d0b221
to
3210f99
Compare
… fields refactor: convert ApolloClient__Core_ApolloClient.res refactor: QueryHookOptions refactor: LazyQueryHookOptions refactor: QueryLazyOptions missed deprecation notices more stuff drop bs-platform support bs-platform 9 -> rescript 9 has been around for quite some time now more changes DataProxy the rest? format again
3210f99
to
ddd0e7f
Compare
Do you want to stick with a binding that says all the properties are always present? I think that's probably fine. Personally, I always added a wrapper around this library to turn these results into a single |
Yeah that seems more correct, and changing the result types seems pretty disruptive to me; same with changing the
Yeah I preferred that too, this used to be built in and was removed at some point. There's definitely a trade-off between ReScript-specific ergonomics and making the bindings look more like regular JS/TS usage for ease of adoption / ability to make the normal docs more relevant to the bindings. |
Sounds good |
Resolves #151
BREAKING: Requires optional record fields support from
rescript@^10.0.0
Potentially disruptive (but hopefully not): Drops peer-dependency for
bs-platform
. It seems pretty likely that most people would be moved to at leastrescript@9
(which was just a re-name) ormelange
by this point.