{"componentChunkName":"component---src-templates-post-tsx","path":"/posts/2019/10/extend-types-typescript/","result":{"data":{"markdownRemark":{"fields":{"slug":"/2019/10/extend-types-typescript/"},"frontmatter":{"title":"Writing declaration.d.ts for JavaScript modules, and Extending incomplete @types modules","tag":["typescript","@types"],"image":"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTzrjWCZNR3zkBb4XyLO-jLQZiV9SI7tV0cV6HxKHXEYyoVDU5p"},"correctedDateEpoch":1572109200000,"html":"<p>If you have used TypeScript long enough, you should realize that you can create <code>declaration.d.ts</code> with <code>declare module 'javascript-module'</code> for untyped JavaScript modules.</p>\n<!-- excerpt_separator -->\n<p>However, you can go far beyond that. Indeed, the best way, if you have time, is to contribute to <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped\">https://github.com/DefinitelyTyped/DefinitelyTyped</a>. However, the process is slow, and can take around 1 week for @types repo to get updated.</p>\n<p>I realized that you can do beyond <code>declare module 'javascript-module';</code> by</p>\n<pre><code class=\"language-typescript\">declare module 'javascript-module' {\n   export = JavaScriptModule;\n\n   class JavaScriptModule {\n   }\n\n   namespace JavaScriptModule {\n        interface IBlahBlah {}\n   }\n}\n</code></pre>\n<p>Now, the typing is in your control.</p>\n<p>Also, if <code>@types/javascript-module</code> is insufficient, you can do this,</p>\n<pre><code class=\"language-typescript\">import JavaScriptModule from \"javascript-module\";\n\ndeclare module \"javascript-module\" {\n    interface JavaScriptModule {\n        additionalMethod: () => void;\n    }\n\n    namespace JavaScriptModule {\n        interface IBlahBlahBlah {}\n   }\n}\n\nJavaScriptModule.prototype.additionalMethod = function() {\n    this...\n}\n</code></pre>\n<p>After all, what I want to say is that you can extend TypeScript.</p>\n<p>Good luck exploring.</p>"}},"pageContext":{"slug":"/2019/10/extend-types-typescript/"}}}