From 920b3d85692da8dd9fad8288de2fe519cd0f6aa0 Mon Sep 17 00:00:00 2001 From: adriancuadrado <29214635+adriancuadrado@users.noreply.github.com> Date: Fri, 9 Jan 2026 23:15:27 +0100 Subject: [PATCH] Moved "Parameter Properties" section above "this Types" In the `this-based type guards`](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-based-type-guards) subsection of the [`this Types`](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types) section there is an example that uses a parameter property. This may confuse readers that are reading this article from top to bottom since you are using a feature that has not been explained yet. --- .../copy/en/handbook-v2/Classes.md | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/documentation/copy/en/handbook-v2/Classes.md b/packages/documentation/copy/en/handbook-v2/Classes.md index da70ad9bd633..ea6562613cbf 100644 --- a/packages/documentation/copy/en/handbook-v2/Classes.md +++ b/packages/documentation/copy/en/handbook-v2/Classes.md @@ -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. @@ -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
@@ -1468,3 +1468,4 @@ fn(window); fn({}); fn(fn); ``` +