Automatically Assign Constructor Parameters as Class Properties in TypeScript #61457
Closed
6 tasks done
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
🔍 Search Terms
Currently, in TypeScript, when we define a constructor (concise way), parameters do not automatically become class properties unless explicitly marked with public, private, or protected.
✅ Viability Checklist
⭐ Suggestion
I propose that constructor parameters should default to public if no access modifier is specified.
This means:
-> Explicit access modifiers (private, protected) should still behave as expected.
->If no modifier is given, TypeScript should automatically treat the parameter as public.
📃 Motivating Example
Current Behaviour:
class Student {
constructor(public name: string, public age?: number, public address?: string) {}
}
Suggested Behaviour:
class Student {
constructor(name: string, age?: number, address?: string) {}
}
💻 Use Cases
Why This Change?
✅ Reduces Redundancy – No need to explicitly write public when it's the default behavior.
✅ Improves Developer Experience – Constructor parameters are typically meant to be class properties, so it makes sense for TypeScript to assume public.
✅ Keeps Code Clean & Readable – Avoids unnecessary boilerplate.
The text was updated successfully, but these errors were encountered: