Tutorial Series

How To Code in TypeScript

Default avatar
By Jonathan Cardoso
Software Engineer - Lindy.ai
How To Code in TypeScript

Introduction

TypeScript is an extension of the JavaScript language that uses JavaScript’s runtime with a compile-time type checker. This combination allows developers to use the full JavaScript ecosystem and language features, while also adding optional static type-checking, enum data types, classes, and interfaces.

This series will show you the syntax you need to get started with TypeScript, allowing you to leverage its typing system to make scalable, enterprise-grade code.

Summary View
detailed View

Series Tutorials

Tutorial

How To Use Basic Types in TypeScript

Published on March 16, 2021

TypeScript is an extension of the JavaScript language that uses JavaScript’s runtime with a compile-time type checker. This combination allows developers to use the full JavaScript ecosystem and language features, while also adding optional static type-checking, enum data types, classes, and interfaces. This tutorial will go through type declaration and all the basic types used in TypeScript.

Tutorial

How To Create Custom Types in TypeScript

Published on March 25, 2021

Though the basic types in TypeScript will cover many use cases, creating your own custom types based on these basic types will allow you to ensure the type checker validates the data structures specific to your project. This tutorial will show you how to use custom types with TypeScript, how to compose those types together with unions and intersections, and how to use utility types to add flexibility to your custom types.

Tutorial

How To Use Functions in TypeScript

Published on April 13, 2021

TypeScript fully supports the existing JavaScript syntax for functions, while also adding type information and function overloading as new features. Besides providing extra documentation to the function, type information will also decrease the chances of having bugs. In this tutorial, you will start by creating the most basic functions with type information, then move on to more complex scenarios, like using rest parameters and function overloading.

Tutorial

How To Use Enums in TypeScript

Published on June 14, 2021

In TypeScript, enums, or enumerated types, are data structures of constant length that hold a set of constant values. Each of these constant values is known as a member of the enum. Enums are useful when setting properties or values that can only be a certain number of possible values. This tutorial will explain the syntax used to create enum types, the JavaScript code that the TypeScript compiler creates under the hood, and a use case for enums in game development.

Tutorial

How To Use Classes in TypeScript

Published on July 10, 2021

Classes are a common abstraction used in object-oriented programming (OOP) languages to describe data structures known as objects. TypeScript has full support for class syntax and also adds features on top of it, like member visibility, abstract classes, generic classes, arrow function methods, and a few others. This tutorial will go through the syntax used to create classes, the different features available, and how classes are treated in TypeScript during the compile-time type-check.

Tutorial

How To Use Decorators in TypeScript

Published on September 17, 2021

Decorators are a way to decorate members of a class, or a class itself, with extra functionality. This tutorial covers creating decorators in TypeScript for classes and class members, and also how to use them.

Tutorial

How To Use Interfaces in TypeScript

Published on October 1, 2021

Interfaces in TypeScript enable you to represent and document various data structures. In this tutorial, you’ll create interfaces, learn how to use them, explore the differences between normal types and interfaces, and learn about declaration merging and module augmentation.

Tutorial

How To Use Generics in TypeScript

Published on November 16, 2021

Generics are a fundamental feature of statically-typed languages, allowing developers to pass types as parameters to a type, function, or other structure. TypeScript fully supports generics as a way to introduce type-safety into components that accept arguments and return values whose type will be indeterminate until they are consumed later in your code. In this tutorial, you will try out real-world examples of TypeScript generics to make your code more re-usable.

Tutorial

How To Use Namespaces in TypeScript

Published on February 2, 2022

In TypeScript, you can use namespaces to organize your code. Previously known as internal modules, namespaces in TypeScript are based on an early draft of ECMAScript modules. In this tutorial, you will create and use namespaces to illustrate the syntax and what they can be used for. It will lead you through code samples of declaring and merging namespaces, how namespaces work as JavaScript code under the hood, and how they can be used to declare types for external libraries without typing.

Check out all our Tutorial Series

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.