microsoft / microsoft/TypeScript-Website

Docs: usage of parameter properties as class members in constructor

Open
#3,041 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.6k
Forks
1.5k
Avg merge
2d 2h
Merged PRs (30d)
7

Description

The docs don't seem to specify from what point onwards (after constructor signature or after constructor execution) parameter properties are available as class members - and hence don't seem to make any indication which of the following is "better":

constructor(private name: string) {
  console.log(this.name);
  console.log(name);
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Parameter Properties section in the TypeScript Handbook linked in the issue, and review how the constructor example is currently explained. Clarify when the parameter property is available as a class member and address whether this.name or the parameter name is preferable. Done means the documentation answers this question with an accurate example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.