Skip to content

Incorrect visibility error when setter precedes getterΒ #49685

@zfeed

Description

@zfeed

Bug Report

πŸ”Ž Search Terms

private/public class property order

πŸ•— Version & Regression Information

  • This is the behavior in every version from 4.3.5 to 4.7.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Example without error
class User {
  #name!: string;

  public get name() {
    return this.#name;
  }

  private set name(name: string) {
    this.#name = name;
  }
}

const user = new User();

// no error
user.name;


// Example with error
class UserError {
  #name!: string;
  
  private set name(name: string) {
    this.#name = name;
  }

  public get name() {
    return this.#name;
  }
}

const userError = new UserError();

// error: Property 'name' is private and only accessible within class 'UserError'.
userError.name;

πŸ™ Actual behavior

If we firstly define a private setter for a property and then a public getter for the same property we receive an error when accessing the getter - Property is private and only accessible within class. If we change the order the error doesn't appear

πŸ™‚ Expected behavior

Any order is acceptable and doesn't produce an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions