-
Notifications
You must be signed in to change notification settings - Fork 10
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
Generic Service/Resource types #502
Conversation
The one bit I wanted to do but couldn't get to work was to give more precise type bounds than Given e.g.
what I have here ( As far as I can tell in typescript docs, there's no way to access the type arguments of a type so as to map each But maybe a typescript wizard knows how to do that? @mbouaziz @skiplabsdaniel |
081d2b7
to
acdccea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, I think the more informative types improve the understandability of the api meaningfully.
Did you mean to not adapt the database example in a similar way to you did for the sum and sheet ones?
acdccea
to
45349cd
Compare
I skipped it because adapting it doesn't add much in the way of clarity or brevity, and the type inference does fine without annotations. But just added equivalent annotations/type aliases there for consistency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. I have an idea to try for the dissatisfaction you noted with the type of initialData, but no need to block this on that.
7dab3c4
to
7e80936
Compare
I tried with type InitialData<Inputs extends NamedCollections> = {
[Name in keyof Inputs]: Inputs[Name] extends EagerCollection<infer K, infer V>
? Entry<K, V>[]
: Entry<Json, Json>[];
};
.
.
.
initialData?: InitialData<Inputs>; and it found type errors in the HN example, probably legit |
Yes, that is the approach I am doing right now, and yeah, those type errors look legit. |
I pushed the approach I tried as #503 . It is not exactly the same as Mehdi proposed, in that I tried to avoid conditional types and |
This PR adds type parameters to the SkipService and Resource types, allowing to give more precise types and stricter checking that keys/types match between
initialData
,SkipService#createGraph
, andResource#instantiate
.E.G. where before we had
and care was required to match up the keys of the various records, as well as the more-precise-than-
Json
types of keys/values, now you can write something likeand define your service as
SkipService<Inputs, Outputs>
to get static checking that the various records agree and that the keys/values have the right type.