Types, Type Systems and TypeScript

Types, Type Systems and TypeScript

A 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

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_](https://en.wikipedia.org/wiki/Type_system)

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Nominal typing in Typescript

Type systems are typically categorized as either structural or nominal. Languages like Java and Scala have primarily nominal type systems, whereas a language like Typescript has a structural type system. Let’s take a brief look at both systems.

TypeScript — Type System

In this lesson, we are going to learn about the fundamentals of TypeScript and how TypeScript manages types. This lesson includes topics such as type assertion, type interference, type unions, type guards, structural typing, and other important concepts that you should absolutely know about.

Functional Programming: Using the Functor Type Class in TypeScript

Functional Programming: Exploring the Functor type class and its use cases

Learn about TypeScript Types in Programming

Basic TypeScript types that developers need to know when working with TypeScript. In this post, we'll Learn about TypeScript Types in Programming

Binary Arithmetic in TypeScript's Type System

Binary Arithmetic in TypeScript's Type System