Parameter Properties
A parameter property is a constructor parameter with public, private, protected, or readonly that also declares and assigns a class field of the same name. It is TypeScript syntax and erases to an ordinary assignment.
Detailed Explanation
The usual class field is two or three lines: a declaration, a constructor parameter, an assignment. Parameter properties collapse that:
class User {
constructor(public readonly id: string, public email: string) {}
}
That is equivalent to declaring readonly id: string and email: string on the class and writing this.id = id; this.email = email in the constructor. The modifier is what flips a parameter into a field. A constructor parameter without a modifier is just a parameter.
All four field modifiers work: public, private, protected, readonly, and combinations (private readonly). The emitted JavaScript is still this.id = id in the constructor body, after super() in a subclass.
Use them for classes that are mostly data: DTOs, small value objects, dependency-injected services whose constructor arguments are the fields. Avoid them when the constructor has to transform the argument (this.email = email.toLowerCase()), when the field name should differ from the parameter, or when the constructor is already crowded with logic. A transform next to a parameter property is easy to miss — the field is assigned the raw parameter first, and your extra line has to overwrite it.
Visibility follows the modifier. constructor(private repo: Repo) makes repo a private field, which is the usual DI style. constructor(repo: Repo) without a modifier does not store repo on the instance.
Parameter properties participate in implements and in strictPropertyInitialization the same way declared fields do. They can have default values (public limit = 10) and optional marks (public name?: string). They cannot use the # private syntax; hash fields are declared in the class body.
Some style guides ban them because they hide field lists. That is a readability trade, not a type-system one. If a class has more than a handful of fields, a visible list is often clearer. If it has two, a parameter property is the smaller file.
Code Examples
1. Shorthand vs the long form — same types, same emit idea.
// 1. Shorthand vs the long form — same types, same emit idea.
class User {
constructor(
public readonly id: string,
public email: string,
) {}
}
const ada = new User("u1", "ada@example.com");
console.log(ada.id, ada.email);2. A parameter without a modifier is not a field.
// 2. A parameter without a modifier is not a field.
class Session {
constructor(id: string) {
console.log(id);
}
}
const s = new Session("s1");
// s.id
// Error: Property 'id' does not exist on type 'Session'.3. Subclass: super first, then parameter properties assign.
// 3. Subclass: super first, then parameter properties assign.
class Admin extends User {
constructor(
id: string,
email: string,
public role: "admin",
) {
super(id, email);
}
}
const admin = new Admin("u2", "grace@example.com", "admin");
console.log(admin.role);Common Gotchas
Forgetting the modifier stores nothing
`constructor(private repo: Repo)` and `constructor(repo: Repo)` look similar and mean different things. The second does not create `this.repo`.
Transforms must overwrite the auto-assignment
`constructor(public email: string) { this.email = email.toLowerCase(); }` works; putting the transform only on the parameter and expecting the field to change does not, unless you assign `this.email`.
`#` fields cannot be parameter properties
declare them on the class body and assign in the constructor.
Large constructors become an implicit field list
reviewers have to read modifiers to know what is stored. Split or write explicit fields when the list grows.