-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: TypeScript support for Collection #81
Conversation
e0ea750
to
457ae0e
Compare
Oh that looks great, thank you for putting that together Munif! I'll test it with my @octokit libraries, which are all written with TypeScript and I use the collection API |
5032b20
to
5477235
Compare
Very sorry Munif, I totally dropped the ball on this one. I'm looking into it now |
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.
Instead of using O, R, E, could you use something more clear, such as TOptions, TResult, TError?
Otherwise this is great, really appreciate the thorough docs updates!
Just to clarify, you want to change the shape of the generic that So, instead of: type HooksType = {
add: { O: { type: string }; R: { id: number }; E: Error };
save: { O: { type: string }; R: { id: number } };
read: { O: { id: number; foo: number } };
destroy: { O: { id: number; foo: string } };
};
const hooks = Hook.Collection<HooksType>(); You want this: type HooksType = {
add: { Options: { type: string }; Result: { id: number }; Error: Error };
save: { Options: { type: string }; Result: { id: number } };
read: { Options: { id: number; foo: number } };
destroy: { Options: { id: number; foo: string } };
};
const hooks = Hook.Collection<HooksType>(); In that case, I think this going to be very verbose, as I need to write this repetative thing. That's why I went with the short names. What do you think about that? Or did you mean to just change the internal names in
to
? |
I think verbosity is better, it makes the code easier to read, and we read code much more often then we write it. It makes the code easier to maintain and contribute to. I try to avoid abbreviations as a general rule, so I would use more verbose type variable names for both, internal usage and the public APIs |
I've changed those to I've also kept the option to use |
Thanks a lot! I'll test your changes with |
It seems to be working while working in TypeScript, but currently my build step with The error I'm getting is
any idea what that could be? |
You probably forgot to pass the type on const hook = new Collection<HookType>() otherwise TypeScript won't let you assign it to the property type on hook: HookCollection<HookType> at this.hook = hook; P.S: You can omit the second generic type from |
That was exactly it. Thank you so much! |
One last question. I think this change is breaking for TypeScript users of the
Is there a simple way to workaround that? No worries if not, I don't consider type-only changes breaking changes, but if it's simple enough, I think it would reduce some friction when people upgrade |
Sure. Making it required was not intentional. Fixed it. |
Sorry @MunifTanjim, I've upgraded
Sounds like an incompatibility with the type parameter names? |
Sorry, was my bad. Missed a spot while making the type args optional. |
That was it, seems all to be working great now! |
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.
Thank you so much, this is really great!
🎉 This PR is included in version 2.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
No description provided.