# TypeScript Compilation — Babel & SWC

Source: https://www.geekswithgeeks.com/en/babel-swc/bs-typescript-compilation

> How Babel and SWC handle TypeScript syntax and type erasure.

## Type erasure: removing types

Babel and SWC **strip** TypeScript syntax but do **not** type-check. They remove `: Type`, `<T>`, `as Type`, etc., leaving plain JavaScript that runs.

## TypeScript to JavaScript transformation

Type annotations vanish; the logic remains. Use `tsc` or IDE for type checking, Babel/SWC for transpilation.

```typescript
// Input: TypeScript
function greet(name: string): string {
  return `Hello, ${name}`;
}

// Output: JavaScript (types gone)
function greet(name) {
  return `Hello, ${name}`;
}
```

## Always use tsc for type checking

Babel and SWC remove types silently. If you have a type error (wrong property name, wrong parameter type), transpilation succeeds anyway. Run `tsc --noEmit` in CI to catch type bugs before shipping.
