> For the complete documentation index, see [llms.txt](https://amnrsln.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amnrsln.gitbook.io/notes/front-end/typescript.md). Agents can also search and read this documentation through its [MCP server](https://amnrsln.gitbook.io/notes/~gitbook/mcp).

# Typescript

## Quick Start

* <https://www.typescriptlang.org/samples/index.html>

## Getting Started:

* <https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html>

### Type annotations:

Type annotations in TypeScript are lightweight ways to record the intended contract of the function or variable.

```typescript
function greeter(person: string) {
    return "Hello, " + person;
}

let user = "Jane User";

document.body.innerHTML = greeter(user);

```

### Interfaces

Two types are compatible if their internal structure is compatible. This allows us to implement an interface just by having the shape the interface requires, without an explicit `implements` clause.

```typescript
interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = { firstName: "Jane", lastName: "User" };

document.body.innerHTML = greeter(user);

```

### Classes

```typescript
class Student {
    fullName: string;
    constructor(public firstName: string, public middleInitial: string, public lastName: string) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
}

interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person : Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = new Student("Jane", "M.", "User");

document.body.innerHTML = greeter(user);
```
