Skip to content

Cannot Optionalize Class Getters #14417

Open

Description

TypeScript Version: 2.2.1

Code

class Person {
  firstName: string;
  lastName: string;

  get fullName?() {
    return this.firstName + ' ' + this.lastName;
  }
}

Expected behavior:

Since fullName is optional the following should work:

const Me: Person = {
  firstName: 'Foo',
  lastName: 'Bar'
}

Actual behavior:

A syntax error occurs on this line get fullName?() {

I'm not sure if omitting the ability to optionalize getters was by design or not. If it was by design, I'd love to know the reasoning behind it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions