Writing npm (JavaScript) libraries using TypeScript
TypeScript is revolutionizing the JavaScript ecosystem. And with more developers writing Node.js projects using TypeScript instead of JavaScript, its important that type definitions for packages are easily available. Sam Lanning dives into Node.js and npm, demonstrating how to create npm packages allowing other developers to easily use the type definitions of your library.
Talk Title | Writing npm (JavaScript) libraries using TypeScript |
Speakers | Sam Lanning (Semmle Inc) |
Conference | O’Reilly Open Source Software Conference |
Conf Tag | Fueling innovative software |
Location | Portland, Oregon |
Date | July 15-18, 2019 |
URL | Talk Page |
Slides | Talk Slides |
Video | |
As an increasing number of developers are writing Node.js projects using TypeScript instead of vanilla JavaScript, it’s becoming more important that type definitions for popular packages are made available for everyone. The DefinitelyTyped project works toward solving this by maintaining a repository of type definitions for thousands of repositories, making them usable in projects by installing a @types package. However, these definitions need to be manually maintained, and as libraries evolve, definitions can get out of sync—not to mention you need to ensure that the version of the package installed matches the installed type definitions, otherwise subtle bugs can occur at runtime. However, TypeScript allows you to include type definitions directly in the package the definitions are describing. Combining this with TypeScript’s ability to automatically generate type definitions ensures you’re always using the correct type definitions for your package, while also removing the manual work of maintaining the definitions separately. Sam Lanning walks you through the process of building and publishing an npm package from scratch using TypeScript. You’ll learn how to export type declarations in a way that allows you to automatically leverage them simply by npm-installing your package.