TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Add Support for Getter and Setter in Ambient Context

Open dneimke opened this issue 10 years ago • 2 comments

As a library developer, I want to provide accurate typing definition files for my components.

The scenario that I cannot achieve this in is where I have a getter and setter on a class declared within an Ambient context.

**foo.d.ts**
// The following gives an error message: 'an accessor cannot be declared in an ambient context'

declare namespace Foo {
    class Widget {
        get name(): string;  // gets the name
        set name(name: string): void;    // sets the name
    }
} 

dneimke avatar Jul 23 '16 01:07 dneimke

My reason for suggesting this change is to support libraries such as kendo.ui:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/kendo-ui/kendo-ui.d.ts#L3373

In that code file, the value property of the DropDownList needs to be set and get'ted using the following syntax:

let foo = dd.value();
dd.value('new value');

dneimke avatar Jul 23 '16 02:07 dneimke

Closing: Adding getter and setter here wouldn't resolve the underlying issue which is described fully here: http://stackoverflow.com/questions/38536989/how-to-create-typescript-type-definition-for-same-named-methods

dneimke avatar Jul 23 '16 02:07 dneimke