Series

TypeScript

Mastering the language of the web. From basic types to advanced generics and patterns.

馃摎 26 Articles
Four JavaScript Challenges for Job Interviews
Typescript From Zero

Four JavaScript Challenges for Job Interviews

During recent developer interviews, I noticed many candidates felt overwhelmed by coding challenges. For junior positions, it's common to be asked about basic JavaScript tasks. Today, I'll share essential data manipulation techniques that junior deve...

How to Detect and Fix Circular Dependencies in Typescript
Typescript From Zero

How to Detect and Fix Circular Dependencies in Typescript

When coding in TypeScript or Angular and embracing types, sometimes we don't pay attention to "Circular dependencies". We create types and try to use them everywhere to match with the existing structure, and if we're not careful, it's so easy to crea...

Why avoid using 'any' in TypeScript
Typescript From Zero

Why avoid using 'any' in TypeScript

When we create applications in Angular, the any type is our "live-saver" when struggle with complex error messages, want to save time by not writing specific type definitions, or think that TypeScript's type checking limits our coding flexibility and...

Combining Types and Interfaces with & or | in TypeScript
Typescript From Zero

Combining Types and Interfaces with & or | in TypeScript

Today, I reviewed a piece of code where a variable could be of two types, but to enhance readability, the simple method is to use union and intersection. In this example, we have defined two interfaces, Player and Basket, each representing a specific...

When Use  Arrays, Tuples, Maps, and Sets In Typescript with Examples
Typescript From Zero

When Use Arrays, Tuples, Maps, and Sets In Typescript with Examples

A few days ago, a friend asked how to prevent duplicate keys in an array, and I told him there are other collections to work with, and each one is suited for a specific situation. Because I love the NBA, I tried to find an easy way to explain each da...

How To Use Record Type In Typescript
Typescript From Zero

How To Use Record Type In Typescript

Today I was facing a problem where I wanted an object with a list of properties but with specific values like: For example: export type NBATeam = "Lakers" | "Celtics" | "Bulls" | "Warriors"; const nbaChampionships = { Lakers: 17, Celtics: 17...

Understand How the Sort Method Operates on Javascript Arrays
Typescript From Zero

Understand How the Sort Method Operates on Javascript Arrays

I was assisting a friend in constructing a sorting table with data in Typescript and he ran into some odd behavior along the way. In this lesson, we will explore what occurs in Javascript when the sort method is used with strings and numbers. Sorting...

How To Check Types In Typescript
Typescript From Zero

How To Check Types In Typescript

In Typescript, we have to check for values types like boolean, string, object instance from class, and the values in objects. 馃憠馃徑 Why pay for hosting? Click here to deploy your Angular apps for free on a reliable VPS In Typescript, we have three w...

3 Ways of Type Transformation in Typescript
Typescript From Zero

3 Ways of Type Transformation in Typescript

When we use types or interfaces, the typescript compiler enforces the object fit with them to avoid runtime errors for missing fields. Sometimes we want the flexibility to create an object without breaking the contract with the interface type. For ex...

Get start with Typescript and Parcel
Typescript From Zero

Get start with Typescript and Parcel

Typescript is a technology that grows every day. Companies like Slack, Airbnb, or Google are changing their javascript codebase to Typescript. Frameworks like Vue, React, and (Angular) are using Typescript for writing maintainable code. These steps s...

How to simplify and organize imports in Typescript
Typescript From Zero

How to simplify and organize imports in Typescript

Sometimes we have a long list of imports, with files that come from the same place, it makes our code noisy and a bit longer, something like: import { BeersService } from './services/beers.service'; import { WhiskyService } from './services/whiski....

Refactor your code using renaming Imports
Typescript From Zero

Refactor your code using renaming Imports

I'm refactoring an Angular code, and I need to have the same filenames while finishing the refactor. My solution was to rename my imports. It is a great way to use a different name or alias for my classes and modules. For example, you can import a si...

Difference between 'extends' and 'implements' in TypeScript
Typescript From Zero

Difference between 'extends' and 'implements' in TypeScript

Today, a friend ask about the difference between extends and implements. class Media { format: string; } class Video extends Media {} class Image implements Media {} The short answer for him was: extends: The class get all these methods and proper...

The Typescript compiler and the tsconfig
Typescript From Zero

The Typescript compiler and the tsconfig

I want to show a small overview of the typescript compiler, and the tsc is responsible for compiling our typescript code, watching changes, code checking, and more. The tsc accept parameters on the execution process can read the configuration from th...

Use fancy imports with path mapping in tsconfig
Typescript From Zero

Use fancy imports with path mapping in tsconfig

In typescript or Angular apps, we can avoid having ugly paths like the following example. import { BookMark } from 'src/app/models/bookmark'; import { BookmarksState } from './../../../state/bookmarks.state'; import { GetBookMark } from './../../../s...

Using Property Decorators in Typescript with a real example
Typescript From Zero

Using Property Decorators in Typescript with a real example

I was talking about class decorators in Typescript in my previous post; today is time for properties decorators to define and use them for writing clean and elegant code. What is Property Decorator The property decorator is a function applied to the ...

Using Class Decorators in Typescript with a real example
Typescript From Zero

Using Class Decorators in Typescript with a real example

The Decorators are an excellent Typescript feature; maybe you see them all over Angular and other frameworks. It helps to write code clean and declarative, maybe you already use it every day, but do you know when to create your decorators? I will s...

Interfaces in Typescript with an Example
Typescript From Zero

Interfaces in Typescript with an Example

The interface is an excellent Typescript feature and helps to write structured and explicit code. The interface helps you describe a structure like fields without values or methods without implementation and forces objects and classes to have. Interf...

Abstract Classes in Typescript
Typescript From Zero

Abstract Classes in Typescript

In Typescript, the classes can inherit from another class to share methods and properties between classes. Also, Typescript support abstract class. Let me show you why and when to use it. For example, we have a base class Subscription and create the ...

Getter and Setter with Typescript
Typescript From Zero

Getter and Setter with Typescript

The encapsulation is an essential part of OOP, and Typescript support gets and sets keywords for members of classes. The encapsulation can be used with the get and set keywords before a function name, then using it. We can encapsulate some logic and ...

How to create type definitions
Typescript From Zero

How to create type definitions

If there is one thing I have to admit, it is that Typescript allows us to feel in control in javascript and that is also thanks to the typings (tsd), but some libraries don't have the typings, I have found myself in need of writing the typings of the...

The functions in Typescript
Typescript From Zero

The functions in Typescript

The Typescript language understands the functions return type by default; for example, in the following example, the compiler understands one return boolean and the other is void. function Auth() { return true } function Auth() { console.log("he...

Using Typescript Types
Typescript From Zero

Using Typescript Types

Typescript comes with its types, and each one is part of typescript, not javascript. Typescript will provide these types as part of our development process, notify the compiler of the data type used, and force us to implement them appropriately. Tupl...

Using type Annotations in Typescript Functions
Typescript From Zero

Using type Annotations in Typescript Functions

I am starting to move to Typescript. I discover how works type annotations in typescript functions. Let start by showing a few things I learned today about Typescript. Typescript allows type annotation in function parameters and returns types. Types ...

Typescript and primitive Types
Typescript From Zero

Typescript and primitive Types

I am starting to move to Typescript. I discover how it works and different ways to use them with Typescript. Typescript is a superset running up to Javascript, and it supports all primitive types. Let start by showing a few things I learned today abo...