Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views2 pages

Typescript

TypeScript is a superset of JavaScript that introduces static typing, allowing developers to catch errors early and improve code maintainability. Key features include static typing, type inference, interfaces, generics, access modifiers, and enum support. TypeScript code is compiled into JavaScript for browser execution, making it beneficial for reducing bugs and enhancing collaboration in larger projects.

Uploaded by

outms437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Typescript

TypeScript is a superset of JavaScript that introduces static typing, allowing developers to catch errors early and improve code maintainability. Key features include static typing, type inference, interfaces, generics, access modifiers, and enum support. TypeScript code is compiled into JavaScript for browser execution, making it beneficial for reducing bugs and enhancing collaboration in larger projects.

Uploaded by

outms437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Here’s a clear, beginner-friendly breakdown of TypeScript.

---

1. What is TypeScript?

TypeScript is a superset of JavaScript — which means it adds extra features to


JavaScript but still works with all existing JavaScript code. The biggest upgrade
it offers is static typing.

Think of it like JavaScript with superpowers:

You can catch errors before running your code.

Your code becomes easier to understand and maintain.

---

2. Key Features

Static Typing – You declare the type of variables, parameters, and function returns
(string, number, boolean, etc.).

Type Inference – TypeScript can guess the type even if you don’t explicitly write
it.

Interfaces – Define structures (shapes) for objects so they must follow certain
rules.

Generics – Make reusable, flexible functions and classes that work with any type.

Access Modifiers – Control how class members are accessed (public, private,
protected).

Enum Support – Create named constants for better readability.

---

3. How TypeScript Works

TypeScript isn’t directly understood by browsers.


You write code in .ts files → TypeScript compiler (tsc) converts it into .js files
→ Browser runs the JavaScript.

Example flow:

TypeScript Code (.ts) → Compiler → JavaScript Code (.js)

---

4. Simple Example

function greet(name: string): string {


return `Hello, ${name}!`;
}

console.log(greet("Alice"));
// console.log(greet(42)); ❌ TypeScript will catch this error before running

In JavaScript, the 42 wouldn’t throw an error until runtime,


but in TypeScript, you’ll know about it immediately during development.

---

5. Why Use TypeScript?

Fewer bugs due to early error detection.

Easier collaboration in teams.

Better auto-complete and suggestions in editors like VS Code.

Scales well for large projects.

---

If you’d like, I can give you a side-by-side JavaScript vs. TypeScript comparison
so you can see exactly what changes. That would make the difference even clearer.

You might also like