revolunet / react-mailchimp-subscribe

React subscribe form for Mailchimp.
https://revolunet.github.io/react-mailchimp-subscribe/
244 stars 48 forks source link

Add TypeScript definitions #34

Open igo opened 5 years ago

igo commented 5 years ago

Please add TypeScript definitions or convert project to TypeScript

Ritural commented 5 years ago

Hey @igo,

This might help if you're looking for a TypeScript definition. This is what I've got if you need a starting point :)

You'll need to create a definition file called react-mailchimp-subscribe.d.ts and include the following code in it

type Status = 'sending' | 'error' | 'success';
type FormData = {
  [key: string]: string;
}

interface IProps {
  url: string;
  render: (props: { subscribe: (formData: FormData) => void, status: Status, message: string }) => React.ReactNode;
}

declare module 'react-mailchimp-subscribe' {
  export default class MailchimpSubscribe extends React.Component<IProps> {};
}
mariano-filipe commented 4 years ago

Regarding the type definitions @Ritural provided, I'd like to add that in case of errors in the jsonp request, the message can also be an instance of Error.

revolunet commented 4 years ago

Pull requests welcome :)