I have the following definition in Typescript
**sample.d.ts**
declare namespace Sample {
class Widget {
name(): string; // gets the name
name(name: string): void; // sets the name
}
}
When I create the following derived Type, I get no warnings:
export class BarWidget extends Sample.Widget {
public name(): string {
return '';
}
}
However, when I create the following Type, I get a Typescript error:
export class FooWidget extends Sample.Widget {
public name(name: string): void {
}
}
The error message is:
Class 'FooWidget' incorrectly extends base class 'Widget'. Types of property 'name' are incompatable. Type '(name: string ) => void' is not assignable to type '{ (): string; (name: string): void;}'
Update:
This question relates to support for 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');
My final solution was to change the definition in kendo.ui.d.ts to:
declare namespace Sample {
class Widget {
name(name?: string):string
}
}