Skip to content

Add Typescript definitions to package - #24

Closed
icopp wants to merge 1 commit into
shutterstock:masterfrom
icopp:add-typescript-definitions
Closed

icopp wants to merge 1 commit into
shutterstock:masterfrom
icopp:add-typescript-definitions

Conversation

@icopp

@icopp icopp commented Dec 11, 2016

Copy link
Copy Markdown

This adds a Typescript definition file for the classes and functions in the module (based off the documentation and by me double-checking against the source), and a typings entry in package.json for it.

This allows anyone using Typescript who installs the module to automatically benefit from these type definitions. It has no effect (negative or positive) on anyone using it with JS.

@dfenster

Copy link
Copy Markdown
Contributor

Thanks @icopp. I'm completely unfamiliar with Typescript or what these declare statements mean. Is there any way to do all this dynamically (for example a npm build script), so that I won't have to maintain the file by hand? Given my lack of experience with this, I don't want to try this and mess it up.

Also, is there anything here that needs tests?

@icopp

icopp commented Dec 18, 2016

Copy link
Copy Markdown
Author

I'm completely unfamiliar with Typescript or what these declare statements mean.

The short version is that the declare module 'xxxx' { ... } tells the Typescript compiler to assume that the module with name xxxx has everything contained there, and the rest is syntactically almost-identical to ES6 Javascript except with the types added (e.g. stuff like function (a) { returns a; } becomes function (a: string): string { returns a; }). The docs for declaration files are pretty good, on that note.

Is there any way to do all this dynamically (for example a npm build script), so that I won't have to maintain the file by hand?

There are scripts that will generate Typescript definitions out of JSDoc annotations, but I'm not sure how reliable they'd be in this case, given the quirks of Typescript definitions I had to work around to make this particular case work (like defining GlobalError, etc).

Also, is there anything here that needs tests?

It might be useful to add something that runs it through tslint to verify the syntax, but other than literally the only point of it is to restate the public members of the module but with those type annotations added, so IMO it'd be hard to come up tests that would actually be useful.

@dfenster

Copy link
Copy Markdown
Contributor

I've been struggling with how to resolve this PR since I know you put a lot of time into this feature, and I don't want to offend you or your efforts. I don't work with TypeScript, which means it would be a bit extra burden for me to maintain this. I also don't believe TypeScript is entirely that popular, so it would affect a minority of coders.

If you would like to maintain a fork, that would be OK with me.

I used http://www.jeffgeerling.com/blog/2016/why-i-close-prs-oss-project-maintainer-notes as a guide to make this decision.

Thanks again for your efforts.

@dfenster dfenster closed this Dec 29, 2016
@jgornick

Copy link
Copy Markdown

@icopp Any chance you could add this to https://github.com/DefinitelyTyped/DefinitelyTyped?

@icopp

icopp commented Feb 24, 2017

Copy link
Copy Markdown
Author

@jgornick It's on the to-do list, just have to find a good time for it.

@icopp

icopp commented Apr 4, 2017

Copy link
Copy Markdown
Author

@icopp
icopp deleted the add-typescript-definitions branch April 4, 2017 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants