function with attribute as method in typescript code example
Example 1: typescript annotate return type
function add(x: number, y: number): number {
return x + y;
}
Example 2: typescript extension getter
interface A {
testGet: SomeType|null;
}
Object.defineProperty(A.prototype, "testGet", {
get (this: A) {
if(this.something) {
return this.something;
}
return null;
},
enumerable: false,
configurable: true
});