{"action":"created","issue":{"url":"https://api.github.com/repos/typings/discussions/issues/21","repository_url":"https://api.github.com/repos/typings/discussions","labels_url":"https://api.github.com/repos/typings/discussions/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/typings/discussions/issues/21/comments","events_url":"https://api.github.com/repos/typings/discussions/issues/21/events","html_url":"https://github.com/typings/discussions/issues/21","id":156066828,"number":21,"title":"Best practices for npm module typing?","user":{"login":"JoshGlazebrook","id":3260991,"avatar_url":"https://avatars.githubusercontent.com/u/3260991?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshGlazebrook","html_url":"https://github.com/JoshGlazebrook","followers_url":"https://api.github.com/users/JoshGlazebrook/followers","following_url":"https://api.github.com/users/JoshGlazebrook/following{/other_user}","gists_url":"https://api.github.com/users/JoshGlazebrook/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshGlazebrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshGlazebrook/subscriptions","organizations_url":"https://api.github.com/users/JoshGlazebrook/orgs","repos_url":"https://api.github.com/users/JoshGlazebrook/repos","events_url":"https://api.github.com/users/JoshGlazebrook/events{/privacy}","received_events_url":"https://api.github.com/users/JoshGlazebrook/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-20T23:09:12Z","updated_at":"2016-05-21T07:59:18Z","closed_at":null,"body":"So I recently started using Typescript and of course I want to use my own packages with it and include the typings files inside the npm package itself.\r\n\r\nMy npm package is designed where the root entry point points to a \"class\" that you use new on to create a new instance of said class.\r\n\r\n```javascript\r\nconst SmartBuffer = require('smart-buffer');\r\nlet buff = new SmartBuffer();\r\n```\r\n\r\nWhat I struggled with was how to properly write the definitions files for it. Do I need to wrap it in a module? Just export declare a class? Eventually I got it to where I can import with typescript like this:\r\n\r\n```typescript\r\nimport SmartBuffer = require('smart-buffer');\r\nlet buff = new SmartBuffer();\r\n```\r\n\r\nAnd vscode/webstorm etc all have intellisense for the instance buff.\r\n\r\nI just wanted to make sure this is the proper way to write the definition files in this particular instance:\r\n\r\nhttps://github.com/JoshGlazebrook/smart-buffer\r\n\r\n(there is only one .d.ts file so it shouldn't be too much of a pain to look through)\r\n"},"comment":{"url":"https://api.github.com/repos/typings/discussions/issues/comments/220764867","html_url":"https://github.com/typings/discussions/issues/21#issuecomment-220764867","issue_url":"https://api.github.com/repos/typings/discussions/issues/21","id":220764867,"user":{"login":"demurgos","id":2262218,"avatar_url":"https://avatars.githubusercontent.com/u/2262218?v=3","gravatar_id":"","url":"https://api.github.com/users/demurgos","html_url":"https://github.com/demurgos","followers_url":"https://api.github.com/users/demurgos/followers","following_url":"https://api.github.com/users/demurgos/following{/other_user}","gists_url":"https://api.github.com/users/demurgos/gists{/gist_id}","starred_url":"https://api.github.com/users/demurgos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demurgos/subscriptions","organizations_url":"https://api.github.com/users/demurgos/orgs","repos_url":"https://api.github.com/users/demurgos/repos","events_url":"https://api.github.com/users/demurgos/events{/privacy}","received_events_url":"https://api.github.com/users/demurgos/received_events","type":"User","site_admin":false},"created_at":"2016-05-21T07:59:18Z","updated_at":"2016-05-21T07:59:18Z","body":"Your `.d.ts` is matching [one of the official examples](https://github.com/typings/typings/blob/master/docs/examples.md#exporting-class--static-methods--utility).\r\nI looked at it and it looks fine.\r\n\r\nI agree that a list of good practices might be useful.\r\n\r\n> Do I need to wrap it in a module? Just export declare a class?\r\n\r\nAs a rule of thumb, the question to ask is \"how `tsc` would have exported my external module if it was written in TS\". In this case I think that a simple class export is the best fit.\r\n\r\nNow, there is one thing I can tell for sure: using `module` is not considered a good practice in `typings`. If you want to declare an namespace for interfaces, use `namespace`. (a `module` declaration can create globals which can lead to conflicts on the consumer side)."}}
{"actor":{"display_login":"demurgos"}}