Fueling innovative software
July 15-18, 2019
Portland, OR

Writing npm (JavaScript) libraries using TypeScript

Sam Lanning (Semmle Inc)
2:35pm3:15pm Thursday, July 18, 2019
Live Coding ONLY
Location: Portland 252
Secondary topics:  Open Source
Average rating: ****.
(4.60, 5 ratings)

Who is this presentation for?

  • Software developers and programmers (especially JavaScript programmers), software architects, CxOs and technical leads, and library and API designers




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.

Prerequisite knowledge

  • A working knowledge of JavaScript, Node.js, and npm
  • Familiarity with the command line
  • Experience publishing npm packages and TypeScript (useful but not required)

What you'll learn

  • Gain insight into the core benefits of TypeScript over vanilla JavaScript and DefinitelyTyped and @types npm packages
  • Understand how TypeScript resolves type definitions for imported modules and how to publish npm packages that automatically include type definitions that TypeScript developers can leverage
Photo of Sam Lanning

Sam Lanning

Semmle Inc

Sam Lanning is a developer advocate at Semmle, which he joined after deciding to drop out of his master’s at Oxford University after completing his undergraduate computer science degree there. He was the first full-time developer for Semmle’s LGTM platform, and he worked on it for over three years before becoming a developer advocate. He’s been an active member of the security and privacy community for a while, with a particular interest in vulnerability research, cryptography, and peer-to-peer networks, having previously contributed to Signal’s Android and desktop clients among other open source projects. In his free time, he’s been working on an open source project that ties together music and lighting.

Comments on this page are now closed.


Picture of Sam Lanning
Sam Lanning | Developer Advocate
07/17/2019 5:13am PDT

All content that I’ll be using for this live coding session can be found on GitHub here: https://github.com/samlanning/typescript-talks/tree/master/writing-npm-libraries-using-typescript

There are instructions, and a Jupyter notebook that can be followed along as I do the presentation.