5 Advanced TypeScript Tips To Make You a Better Programmer

5 Advanced TypeScript Tips To Make You a Better Programmer

Reduce bugs, write more explicit and understandable code, and stop reinventing the wheel using these advanced tips.

Typescript is an amazing language — one that allows us to do everything JavaScript can in a tenth of the debugging time. These tips will mostly be for:

  • reducing bugs, by writing more explicit and understandable code
  • pack more value into your code without reinventing the wheel.

If you already know these, then congrats! You’re a TS Legend — maybe share some of your wisdom with me in the comments ( and read my other article with 5 seperate tips!).

Here’s 5 advanced TypeScript tips that will allow you to write better TypeScript Code.

1. The “is” operator / Type Guards

Swagger is really, really helpful to see what the backend is going to serve you — but, more often than not, programmers are given bad or inconsistant API’s to use, where properties may or may not exist or different objects are returned depending on status.

Unfortunately, there’s no way to catch these at compile time if you don’t know what might come out of the API, but we can make it easy to handle (and report!) at runtime.

API’s are often an entrypoint for errors for typescript — API call results are usually casted like the following:

const myApiResult = await callApi("url.com/endpoint") as IApiResult

or even worse…

const myApiResult = await callApi("url.com/endpoint") as any

typescript programmer programming

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

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

What is TypeScript? Why TypeScript? and Why Not TypeScript?

TypeScript extends JavaScript by adding Types. There are many great reasons to switch to TypeScript. Especially if your team uses JavaScript. There are some reasons to not use TypeScript as there are with any language or framework.

Functional Programming: Using the Functor Type Class in TypeScript

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

Coding 101: Programming Language Building Blocks

This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!

Microsoft Releases TypeScript 4.0 With Speed Boosting Features

Microsoft recently announced the availability of TypeScript version 4.0, an open-source language that is built on top of JavaScript.

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