Best Practices

Error TS1196: Catch clause variable type annotation

Best Practices

By default, TypeScript’s compiler doesn’t allow you to add a custom type annotation to an error in a try-catch statement (TS1196). That’s because the underlying code can throw any type of error, even system generated exceptions, which makes it impossible for TypeScript to know the error type from the start. Luckily, there is the concept called “type guards“ which can help the TypeScript compiler to infer a specific type.

Continue reading →

Improve your switch cases with TypeScript

Best Practices

In this tutorial Benny shows you simple techniques on how to improve your switch statements. Using the tips and tricks from the video, you will never miss a switch case again. You will also learn how to fix error TS2322, TS2366 and TS7030.

Continue reading →

When to use static methods in TypeScript?

Best Practices

When developing class functions that don’t rely on an internal state, it’s a good idea to turn them into static methods. This can be easily done by adding the keyword static to your function’s declaration.

Continue reading →