We talked through a recent PR I created to add TwoSlash support for Josh's expect-type eslint plugin. That syntax looks like this:
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:
- It uses a widely-adopted syntax (TwoSlash is even supported on the TypeScript playground).
- It's implemented through an eslint plugin, so you don't need another tool to make type assertions.
- 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!