Cherry/report-to

TypeScript support

Closed this issue ยท 7 comments

It would be great to have TypeScript support : )

Thanks for the suggestion @hongbo-miao! I don't personally use TypeScript so won't be adding this myself any time soon unfortunately, but would encourage a PR if you wish to add this functionality.

Hey @Cherry, I'd be happy to add the declarations to this module as I did with the network error logging middleware if you wanted! Just let me know and I can get started, it likely wouldn't take long now that I know how to go about it ๐Ÿ˜„

@aaronleopold That'd be very much appreciated, thanks! Let me know if you have any questions about the schema.

group, and include_subdomains on a specific group inside groups[] are optional. priority and weight inside endpoints are optional. The validate file holds most of this info today and the docs aren't quite as verbose at network-error-logging.

I think I got the objects structured correctly, let me know what you think:

type Endpoint = {
	url: string; // required
	priority?: number; // optional
	weight?: number; // optional
};

type Group = {
	max_age: number; // required
	endpoints: Endpoint[]; // required
	include_subdomains?: boolean; // optional
	group?: string; // optional
};

type OptionsConfig = {
	groups: Group[]; // required
};

The types are registering correctly in the test file I converted over to TS, but because the types are more nested they aren't exposed as readily. For example, the type definition for groups will only show if I get it wrong, otherwise it will just label it as Group[] without exposing the full typing. I don't expect this to be too bad, but I decided to export the types along with the function to help ease this. I would also be able to remove some of the separation if you wanted it more readily available, something along the lines of this to try and expose the definition better:

type OptionsConfig = {
	groups: {
            max_age: number; // required
	    endpoints: Endpoint[]; // required
	    include_subdomains?: boolean; // optional
	    group?: string; // optional
        }[]; // required
};

That looks great to me @aaronleopold, thanks for the info! I'm going to lean heavily on what you think would be best here, unless @hongbo-miao has any insight. ๐Ÿ‘

Yeah it looks good!

Alright then, I went ahead and made a pull request (#31)! Let me know if there is anything I missed or anything you might want me to change ๐Ÿ˜„