TypeScript: Seeing Past The Hype
Matthew Gerstman
Senior Software Engineer at Dropbox
- 🗽 NYC
@MatthewGerstman
- 📊typescript.matthewgerstman.com





bit.ly/broadway-book
Thank you for indulging me
Typescript




Google Trend

Today We're Going To Get Past The Hype


We're gonna go into the ugly parts, and then talk about why it's worth it anyway.
I want to convince you this tool is worth learning and using.
Let's take 10 steps back
What is a type?
A type is an attribute of data that tells the computer how the programmer intends to use it.
Basic Types
Falsy Types
Types can also be derived from other types
Any

What is TypeScript?
Strict superset of JavaScript
It's smart, really smart.
It makes big refactors easy
Demo: VSCode + Typescript
Slytherin.dev
TypeScript is going to get in your way for the first few months
lodash.get/set
Tests require very well mocked data or lots of anys
Advanced JavaScript translates to advanced TypeScript
Higher Order Components
This is hard to type

Blogpost:
bit.ly/ts-hoc
TypeScript is not Sound!
Anyone can put an any in your codebase.

React Context
React-Redux
Context
Thunks
Dispatch
TypeScript is a strict superset of JavaScript
We're bolting on types to an untyped language
Valid JavaScript
All of this is still worth it.
TypeScript is just another tool
TypeScript is not a silver bullet
TypeScript eliminates a class of bugs
undefined is not an object
variable is not a function
Changing Interfaces
Dropbox Scale
Typescript is a core part of our frontend workflow
Library Upgrades
DefinitelyTyped

The first thing we do when upgrading a library is swap out the types.
TypeScript catches the vast majority of breakages when upgrading a library.
Examples
At our scale I don't know how we would upgrade libraries without TypeScript
TypeScript allows us to place constraints on engineers.

Problem
We want to test the latest version of React in production.
But we might need to roll back.
Developers will start using shiny new features as soon as we let them.

Solution
Roll out latest version behind a feature gate.
Keep the previous version of React's Types.
When we're confident it works, add the types.
Restrict Lodash Usage
Blogpost:
bit.ly/db-lodash
What about for small teams?
Free Documentation
Free Documentation
Free Tests
Free Tests
Contract Validation
A Contract is precise and verifiable interface for software components.
Verifiable
Api
Component Library
Feature
Sample App
TypeScript increases in value over time

Unlike tests, typescript gets in your way
TypeScript is not a silver bullet!
The metric for success on a codebase is how few things you need to keep in your head at a time.
TypeScript allows you to forget about other parts of your codebase
The cost of TypeScript is learning it.

Matthew Gerstman
Senior Software Engineer at Dropbox
- 🗽 NYC
@MatthewGerstman
- 📊typescript.matthewgerstman.com
References
https://en.wikipedia.org/wiki/Data_type
https://blogs.dropbox.com/tech/2018/09/migrating-from-underscore-to-lodash/
https://twitter.com/MatthewGerstman/status/1087928519592722432?s=20
https://news.ycombinator.com/item?id=18975373
https://medium.com/javascript-scene/the-typescript-tax-132ff4cb175b
https://en.wikipedia.org/wiki/Design_by_contract
https://medium.com/@jasvir/monoglots-when-a-subset-is-not-1604e3a51d9