Skip to content

Accessors on class declarations #10969

@apazureck

Description

@apazureck

Dear sirs,

Would it be possible to add a get and set semantic on declaring classes? I was writing typescript declarations for the openUI5 project. They do not use the ECMA5 syntax property specification, but they use a getProperty setProperty syntax. I did not find any solution for this problem so far (maybe I am overlooking something).

It would be great to reflect these getters and setters as a property, as it would reduce the methods exposed via intellisense and creating a usage close to existing typescript classes.

Suggested Typescript Syntax

declare class ClassName {
  get PropertyName getMethod(): type;
  set PropertyName setMethod(value: type);
}

Example
_Javascript file to declare_

function Text() {}

Text.prototype.getText = function () {
    return this.Text;
}

Text.prototype.setText = function (value) {
    this.Text = value;
}

_Declaration file_

declare class {
  get Text getText(): string;
  set Text setMethod(value: string);
}

_Usage in Typescript file_

var helloworld = new Text();
text.Text = "Hello World";
alert(text.Text);

_Compiled output (Javascript)_

var helloworld = new Text();
text.setText("HelloWorld");
alert(text.getText());

Sources:
http://stackoverflow.com/questions/39534455/is-it-possible-to-have-getters-and-setters-in-typescript-declaration-file/39535551#39535551
https://github.com/apazureck/ui5.d.ts/tree/master/UI5Application1/UI5Application1/Scripts/typings/ui5

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions