Does TypeScript Check Types on Runtime?

TypeScript does not check types on runtime (because it is not one of its design goals). In fact, it removes type annotations, interfaces, type aliases, and other type system constructs during compilation. This means that Typescript compiles to pure Javascript, and JavaScript does not know anything about the types at runtime (as they are erased).

TypeScript actually only performs static type checking at compile-time. The idea is that if the scripts pass static type checking, then some level of type safety is guaranteed for inputs.

An important thing to note here is that, if you have the noEmitOnError option set to false (which is the default) in your tsconfig file, it will emit compiler output files (like JavaScript source code, source-maps or declarations) even if any errors are reported at compile-time.

There are of course ways to achieve some level of type safety at runtime as well. For example, you could consider the following:

Hope you found this post useful. It was published . Please show your love and support by sharing this post.