# TypeScript

#### What is TypeScript?

TypeScript is a superset of JavaScript developed by Microsoft that adds static types to the language. It is designed for the development of large applications and transcompiles to JavaScript.

#### TypeScript vs. JavaScript

* **Static Typing**: TypeScript introduces static typing, allowing developers to define types for variables, function parameters, and return values. JavaScript is dynamically typed.
* **Class Features**: TypeScript supports modern JavaScript features as well as additional features such as enums and interfaces, providing more tools to catch errors at compile time.
* **Tool Support**: TypeScript offers enhanced autocompletion, navigation, and refactoring services in editors, thanks to its type information.
* **Compatibility**: TypeScript code is compiled down to JavaScript, making it compatible with any JavaScript environment.
* **Learning Curve**: JavaScript developers may face a learning curve with TypeScript's typing system and additional features, but the core language remains familiar.

#### Current Uses of TypeScript

* **Web Development**: Widely used in front-end and back-end development for structuring large and complex web applications.
* **Frameworks and Libraries**: Many popular frameworks and libraries like Angular, React (with TypeScript definitions), and Vue.js support or encourage using TypeScript for development.
* **Enterprise-Level Applications**: Its static typing and object-oriented features make TypeScript an ideal choice for enterprise-level applications that require maintainability and scalability.

```typescript
// Example of integrating TypeScript with a webpage

// Define an interface for a user
interface User {
  name: string;
  age: number;
}

// A function that takes a User object and returns a greeting message
function greetUser(user: User): string {
  return `Hello, ${user.name}! You are ${user.age} years old.`;
}

// Creating a User object
const user: User = {
  name: "John Doe",
  age: 30
};

// Using the function and displaying the greeting in the webpage
document.body.innerHTML = greetUser(user);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/web-development/scripting-languages/typescript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
