My Twitch Debut (eslint-plugin-expect-type with Josh Goldberg)

I made my Twitch debut last week with Josh Goldberg, who's writing O'Reilly's upcoming Learning TypeScript title.

We talked through a recent PR I created to add TwoSlash support for Josh's expect-type eslint plugin. That syntax looks like this:

let four = 4;
// ^? let four: number

The eslint plugin will then check that TypeScript reports let four: number when you get quickinfo for four. This lets you write tests for the display of types. The idea is similar to dtslint and literate-ts, but with a few key advantages:

  1. It uses a widely-adopted syntax (TwoSlash is even supported on the TypeScript playground).
  2. It's implemented through an eslint plugin, so you don't need another tool to make type assertions.
  3. It has an autofixer, which makes this pleasant to use.

Once the PR is merged, this will be my new preferred way to test types, and I'll have to update the recommendations from my TSConf 2019 talk as well as Item 52 in Effective TypeScript ("Be Aware of the Pitfalls of Testing Types"). I'm already using it on my latest open source project, crudely-typed (more on that soon!).

I had a great time chatting with Josh, and I think we both learned a thing or two. Hopefully you will, too!

Like this post? Consider subscribing to my newsletter, the RSS feed, or following me on Twitter.
Effective TypeScript Book Cover

Effective TypeScript shows you not just how to use TypeScript but how to use it well. Now in its second edition, the book's 83 items help you build mental models of how TypeScript and its ecosystem work, make you aware of pitfalls and traps to avoid, and guide you toward using TypeScript’s many capabilities in the most effective ways possible. Regardless of your level of TypeScript experience, you can learn something from this book.

After reading Effective TypeScript, your relationship with the type system will be the most productive it's ever been! Learn more »