On this page:
5.1 What is This Assignment’s Purpose?
5.2 Task
5 TypeScript
5.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?

5.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 does this feature in TypeScript conflict with the type checker we have seen until now?

Your answer should not simply be that TypeScript has union types. There’s a more detailed answer than just that.