The TypeScript compiler performs a task called type erasure, which removes all types from the output (see note below). There are two key reasons for this:
- Type information cannot logically be represented in JavaScript
- Type information is intended for the compiler, not for runtime, so it isn't needed in the output
There have been some projects that intended to bring TypeScript's types to the runtime in order to perform runtime-type-checking, but there honestly wasn't a great appetite for this. Given we are moving from totally dynamic types at all times to static type checking at design/compile time, the leap may be big enough for the majority of people.
Types aren't the only thing that can be removed during compilation; another example is uninitialized class members, such as the name property in the example below, which you won't find in your JavaScript file.
class Example {
public name: string;
}
const example = new Example();
console.log(example.name);
But most of the removals in your application will be types and ambient declarations.
The Note Below
All types are erased? There is some experimental support for emitting type information to be used with reflection, which you can try with the reflect-metadata package.