Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions packages/documentation/copy/en/handbook-v2/Classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,29 @@ This method makes the opposite trade-offs of the arrow function approach:
- Only one function per class definition gets allocated, rather than one per class instance
- Base method definitions can still be called via `super`.

## Parameter Properties

TypeScript offers special syntax for turning a constructor parameter into a class property with the same name and value.
These are called _parameter properties_ and are created by prefixing a constructor argument with one of the visibility modifiers `public`, `private`, `protected`, or `readonly`.
The resulting field gets those modifier(s):

```ts twoslash
// @errors: 2341
class Params {
constructor(
public readonly x: number,
protected y: number,
private z: number
) {
// No body necessary
}
}
const a = new Params(1, 2, 3);
console.log(a.x);
// ^?
console.log(a.z);
```

## `this` Types

In classes, a special type called `this` refers _dynamically_ to the type of the current class.
Expand Down Expand Up @@ -1222,29 +1245,6 @@ if (box.hasValue()) {
}
```

## Parameter Properties

TypeScript offers special syntax for turning a constructor parameter into a class property with the same name and value.
These are called _parameter properties_ and are created by prefixing a constructor argument with one of the visibility modifiers `public`, `private`, `protected`, or `readonly`.
The resulting field gets those modifier(s):

```ts twoslash
// @errors: 2341
class Params {
constructor(
public readonly x: number,
protected y: number,
private z: number
) {
// No body necessary
}
}
const a = new Params(1, 2, 3);
console.log(a.x);
// ^?
console.log(a.z);
```

## Class Expressions

<blockquote class='bg-reading'>
Expand Down Expand Up @@ -1468,3 +1468,4 @@ fn(window);
fn({});
fn(fn);
```