Testing static types in TypeScript

By Dr. Axel Rauschmayer


Warning: This is experimental work. Read the comments for more information on its limitations.


In this blog post, we’ll examine how we can test static types in TypeScript (inferred types, etc.). For example, given the following function:

function createPoint(x: number, y: number) {
  return {x, y};
}

We’d like to check in a unit test that TypeScript infers this return type:

{x: number, y: number}

In order to do that, we need a few tools that we are going to look at first.

Source:: 2ality