How to read TypeScript errors and not get mad?
Tags: typescript, errors, guide
Published: 2020-05-28 16:18:32

---
title: How to read TypeScript errors and not get mad?
published: true
date: 2020-05-28 15:31:03 UTC
tags: typescript,errors,guide
canonical_url: https://krzysztofzuraw.com/blog/2020/how-to-read-typescript-errors
---

If you are working with TypeScript I bet you come across such compilation errors:

[![rxjs error](https://krzysztofzuraw.com/static/5b17e265d68265c0c498381d7b5fec88/fcda8/error.png "rxjs error")](/static/5b17e265d68265c0c498381d7b5fec88/cb425/error.png)

Sometimes TypeScript has a lot to say when it is throwing an error so community even made some [stickers](https://github.com/orta/typescript-stickers):

![typescript error](https://raw.githubusercontent.com/orta/typescript-stickers/master/images/2x1%20Inch%20Rectangle%20alt%202.png)

In my blog post, I want to present some advice on how to deal with them. Let me start with the first advice:

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#you-are-not-so-special)You are not so special

I bet you heard this advice many times but the idea here is that everyone is experiencing those errors. Don’t get hard on yourself. Instead, poke on the search engine of your choice for similar issues. Howto do it? I recommend that you look at the end of a stack trace and copy this line. You may need to format error a little bit. I mean removing names of your types of paths that only exists on your local machine. You can search stack overflow too. If that fails I recommend you use [TypeScript discord](https://discord.com/invite/typescript) or you can write to the author of this blog post 😅.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#you-still-get-this-annoying-error)You still get this annoying error

Even you post our problem everywhere and you look under every stone on the internet - you still get the problem. What to do? I recommend (and this is relevant when you want to post to SO or TypeScript discord) that you see in what context this error is occurring. Typically when I got a `tsc` error it is because:

- I’ve updated an external library
- I got something wrong with RxJS and redux-observable
- I’ve error from a library inside `node_modules`
- I’ve ramda types error (many times ramda functions are typed of any or `{}`/`unknown`)

You can also see in which case error occurs? It is when you add type to e.g function definition or maybe the error is later in the codebase when this function is executed? If your codebase is large VSCodecan get stuck so running `tsc` from the command line to see if the bug is occurring helps too. If this fails - you can use the last hope technique.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#the-last-hope)The last hope

‘Last hope technique’ is using `any`. Use `any` as a type to suppress your error for now and move on. You can go back to the problem tomorrow with a fresh mind. Or ask your colleagues or do advice from the first paragraph. Lastly, you can add [ts-expect-error](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments) or `@ts-ignore`.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#summary-and-tldr)Summary and TL;DR

In this blog post I presented a few ways of dealing with annoying or hard errors while using TypeScript:

- don’t get hard on yourself
- seek help on the search engine, stack overflow or community forum
- see the context where this error occurs
- use `any` to move on and then come back to the error