TypeScript abstract method using lambda/arrow function TypeScript abstract method using lambda/arrow function typescript typescript

TypeScript abstract method using lambda/arrow function


My understanding of Typescript specifications is that when you are declaring

public def = (): void => {    this.setting = false;}

You are actually declaring a property called def and not a method on the Base class.

Properties cannot (unfortunately IMHO) be abstracted in Typescript: https://github.com/Microsoft/TypeScript/issues/4669


You can use an abstract property:

abstract class Base {        abstract def: () => void; // This is the abstract property}class Concrete extends Base {    private setting: boolean;        public def = (): void => {        this.setting = false;    }}var myVar: Base = new Concrete();myVar.def();console.log((myVar as any).setting); // gives false


You could do that starting typescript 2.0. In order to make that work you would need to declare a type for your arrow function

type defFuntion = () => void;

then declare

abstract class Base {    abstract abc(): void;    abstract readonly def: defFuntion;}

here is a reference for this feature