ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

Expose TypeScript types for library use #142

Closed bbugh closed 5 years ago

bbugh commented 5 years ago

๐ŸŽ‰๐ŸŽ‰ TypeScript, yay! ๐ŸŽ‰๐ŸŽ‰

However, the package.json doesn't expose the typings, so trying to use them in a project doesn't work.

This pull request makes a tiny change to package.json to tell TypeScript where the types are, so when you import this library into a new project, it Just Worksยฎ without @types/rot-js.

The package.json didn't appear to be in any particular order so it was difficult to guess the best place to put it, so I put it at the bottom.

ondras commented 5 years ago

Hi @bbugh !

I am still pretty new to TS, so I have no idea what the best practices regarding publishing types are. I hope that having them within the project is sufficient, so that the dedicated @types/rot-js might not be needed anymore.

Thanks for your contribution! package.json is automatically re-ordered (alphabetically) by npm every time one makes any npm-based change (such as npm i -S), so the manual order is really not relevant at all.

bbugh commented 5 years ago

Great! I've been using the project types for the last day and so far haven't ran into any issues. Having them published with the project is definitely the preferred way - they're guaranteed to be in sync with the project itself without any extra effort. DefinitelyTyped is great, but often requires extra maintenance and effort to keep it in sync. If a package can publish their own types, it's a big win for everybody.

Having the types key in package.json is the TypeScript-recommended way of publishing, which you can see here: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html