# Decorators at a Glance — TypeScript

Source: https://www.geekswithgeeks.com/en/typescript/ts-decorators

> Functions that attach metadata or behavior to classes — the backbone of Angular.

## What's a decorator?

A **decorator** is a special function, prefixed with `@`, that wraps a class or member to add behavior or metadata without changing its source. Angular uses them heavily — `@Component`, `@Injectable`, `@Input`.

## A simple class decorator

A decorator is just a function that receives the class and can inspect or modify it.

```typescript
function Logged(constructor: Function) {
  console.log(`Class defined: ${constructor.name}`);
}

@Logged
class Greeter {
  greet() {
    return "Hello!";
  }
}
// Output: Class defined: Greeter
```

## Enable them in tsconfig

Legacy decorators need `"experimentalDecorators": true` in `tsconfig.json` — Angular CLI projects set this for you automatically.
