# TypeScript Compilation — बेबल और SWC

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

> कैसे Babel और SWC TypeScript syntax और type erasure को संभालते हैं।

## Type erasure: types को हटाना

Babel और SWC TypeScript syntax को **strip** करते हैं लेकिन type-check **नहीं** करते। वे `: Type`, `<T>`, `as Type`, आदि को हटाते हैं, plain JavaScript छोड़ते हैं जो चलता है।

## TypeScript को JavaScript में transformation

Type annotations गायब हो जाते हैं; logic बना रहता है। Type checking के लिए `tsc` या IDE का उपयोग करें, transpilation के लिए Babel/SWC।

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

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

## Type checking के लिए हमेशा tsc का उपयोग करें

Babel और SWC types को silently हटाते हैं। यदि आपको type error है (गलत property नाम, गलत parameter type), transpilation anyway सफल होता है। Type bugs को ship करने से पहले पकड़ने के लिए CI में `tsc --noEmit` चलाएँ।
