Skip to content

Automatically Assign Constructor Parameters as Class Properties in TypeScriptΒ #61457

Closed
@Phaneendra-Pallapothu

Description

@Phaneendra-Pallapothu

πŸ” 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions