Interfaces and type aliases are used only for type checking during compile time. They do not produce any JavaScript code.
Classes, enums, functions, variables, objects, and arrays exist at runtime in JavaScript.
interface Person {
name: string;
age: number;
}
const user: Person = { name: 'Alice', age: 30 };
console.log(user);The interface is removed during compilation. The object user remains and is logged as expected.
type ID = number | string; const userId: ID = 123; console.log(typeof userId);
The type alias ID is removed during compilation. The variable userId holds the number 123, so typeof userId is "number".
Interfaces and type aliases are only for type checking and are removed during compilation.
Enums, namespaces, classes, functions, variables, and constants generate JavaScript code.
TypeScript types are erased after compilation and only help during development for type safety.
Interfaces and type aliases do not produce JavaScript code.