What is it all about?

type system is a set of rules for performing various consistency and correctness checks in a program. There are various definitions and classifications for type systems. A good working definition is the following:

_In programming languages, a type system is a logical system comprising a set of rules that assigns a property called a “type” to the various constructs of a computer program, such as variables, expressions, functions or modules. — _Wikipedia

There are different categorizations of type systems including:

  • Static vs. Dynamic
  • Structural vs. Nominal
  • Strong vs. Weak (this is more contentious)

Click here for a comparison of various programming languages and their type systems

Structural vs. Nominal

In a _Nominal type system, _all types are either declared or named explicitly. This type of system is used both for determining equivalence between two items, as well as sub type relationships. The majority of statically typed languages (including Java, C, C#, and Rust) use this type of system.

The_ structural type system _is based on properties of the type and any item matching the properties can pass the equivalence test. **TypeScript **(_Go is another language) _uses a structural type system.

To better understand this, let’s define an interface to capture any I/O response and also implement a class HttpResponse for this interface.

Now a function that will take IOResponse as an argument and print the details.

Image for post

#type-systems #programming #typescript

Types, Type Systems and TypeScript
1.75 GEEK