On this page:
4.1 What Is This Assignment’s Purpose?
4.2 Task
4 TypeScript🔗
4.1 What Is This Assignment’s Purpose?🔗

“Dynamic” or “scripting” languages pose special challenges to classical type systems. Some of these are an artifact of trying to add types to a language that was designed without them and wanting to not reject a large part of the existing codebase. We want you to study one such feature.

One consequence of this accommodation is this. If languages are going to add type systems eventually anyway, perhaps they should be designed with types in the first place?

4.2 Task🔗

In TypeScript 2.0, Microsoft introduced a notion called control flow based type analysis (search for it in the document if the link doesn’t work). There are similar features in Facebook’s Flow checker—hence its name—and in JetBrains’s Kotlin. You can read more about this on the Web.

You can play with TypeScript online. For instance, in this program, you can hover over variables and see the typehints.

How is this feature in TypeScript different from the traditional type checker introduced in the book and course? Consider the implications of adding union types to a language.