-
Notifications
You must be signed in to change notification settings - Fork 110
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
Expose types #300
base: master
Are you sure you want to change the base?
Expose types #300
Conversation
Hello, @JakeSidSmith thank you for working on this and excuse me for writing a comment before you asked for the review, I just want to save some of your time. import { MailgunMessageData, MessagesSendResult } from 'mailgun.js/interfaces/Messages';
...
const sendEmail = async (messageBody: MailgunMessageData): Promise<MessagesSendResult> => {
const res: MessagesSendResult = await mg.messages.create(domain, messageBody)
console.log(res);
return res;
}; Also renaming the interfaces folder to the types is a breaking change because people may already have imports from this folder. |
Hey, @olexandr-mazepa, thanks for the quick response. 😁 I understand what you're saying about being able to import from If you were to document it, you then run into the above issue you've highlighted, where you cannot refactor the structure of your library because users are already using that directory structure. It's also not obvious which, if any, of those directories/modules I can/should import from. Presumably some of the other files should not be imported from directly as you want to conceal the implementation and only expose the API you want your users to utilize. Anyway, those are a few of my reasoning behind the change, but the main one is accessibility. Using an editor like VSCode, with intellisense, I've become accustomed to writing out the name of a thing I want to use, and expect my editor to add the import for me, but the types within I'd be happy to change the directory name back to Exporting them all as is I have in this PR may not be the ideal approach. Perhaps you'd prefer them namespaced? Happy to figure that out together. 😊 Side note: importing from lots of sub-modules also crowds your imports a bit, and doesn't allow people to easily namespace your types e.g. |
Okay, I got the idea and it makes sense to me.
And the last one I like the idea of using namespaces and hiding some interfaces that aren't useful for client code like descriptions for API responses but I don't want to make your hard time working on current changes. |
@olexandr-mazepa I'm happy to help out, even in non-billable hours. 😊 If there are some types that you don't want exposed to the world (those used internally by functions for example) you can use this compiler option coupled with doc comments to prevent the types being exported, which would also reduce the size of your published package. I won't have a chance to look a this until this weekend probably, but will see what I can come up with then, that would maintain some backward compatibility. |
Still been super busy, but thought I'd share what I'm working with for the moment. To avoiding using the internals I'm doing the following to alias the types I needed: const client = mailgun.client({/* etc */});
type MailgunMessageData = Parameters<typeof client.messages.create>[1];
type MessagesSendResult = Awaited<ReturnType<typeof client.messages.create>>; |
It's also possible to define the types without a client instance if needed: import Mailgun from 'mailgun.js';
type MailgunClient = ReturnType<Mailgun['client']>;
type MailgunMessageData = Parameters<MailgunClient['messages']['create']>[1]; |
Overview
Expose all types so these can be used by the consumer.
Use case
I want to wrap my Mailgun calls in another function that's functionality differs per environment. In the below case I cannot import
MailgunMessageData
orMessageSendResult
that are used by thecreate
method.Changes
As part of this change this PR also:
interfaces
directory totypes
as it also containstype
aliases andenum
definitionstypes/list.ts
ValidationResponse
->ListValidationResponse
types/list.ts
ValidationResult
->ListValidationResult
types/Webhooks.ts
ValidationResponse
->WebhooksValidationResponse
I don't believe any of these changes to be breaking changes as none of the changed types/paths were previously exposed and should be considered internal.