TypeScript 101 📖

Hi there 👋

So I hear you need to learn TypeScript? Good news, you're in the right place. Before we get started, make sure you're comfortable with JavaScript basics as you will need this this to kick off your TypeScript journey.

By the end of this article, you should:
Use this checklist to monitor your progress ✅

What is TypeScript? 💻

TypeScript is a superset of JavaScript that uses static typing to define types within your JavaScript application. When compiling, TypeScript checks if the types match to help prevent errors within your code.

You must declare the type when you write your code as this cannot be changed during the execution of the program.

Why do we use it? 🤔

Using types within your JavaScript code adds an additional layer of testing to your application as you can find errors more effectively when compiling. It also allows you to write higher quality and more manageable code.

Using type annotations will help improve your code documentation for other developers to see how your code works.

If you want to scale your application to a larger size, creating a clear and concise structure will help with managing large codebases.

TypeScript also provides better tooling support, such as autocompletion and refactoring.

Fundamentals ❗

Once you understand the key Types and Annotations, you will be able to start building your applications within TypeScript as well as updating your current JavaScript projects.

Basic Types

Advanced Types

Type Inference

TypeScript has a feature that can automatically infer the type based on the value that has been assigned. It works by trying to find the best common type that the value can be assigned to by using context.

I know what you're thinking, if this exists, why do we need to define types ourselves? Here's why we should explicitly define our types:

Function Parameter Annotations

These are used to specify function parameters and the types of values they expect to receive.

Variable Annotations

These are used to define the type of variable used.

Interface

These are used to define the shape of an object and specify the properties and methods the object is expected to have. The purpose of an interface is to check types and catch errors during development.

Well done!! 🥳

Now it's time to become a TypeScript Expert. Use the flashcards below to test yourself and create some questions of your own

Question
Answer

Add New Flashcard