TypeScript uses {} for object declaration.

class Point {
    x: number;
    y: number;
    private myAdd = function(x: string, y: string): void { console.log(x + y); }
    Invoke(x, y) { this.myAdd(x, y) }
}
let point:Point = {x:0,y:10, 
     myAdd (x: string, y: string): void { console.log(x + y); },
    Invoke(x, y) { this.myAdd(x, y) }};

error message: error TS2322: Type"{x: number; y: number; myAdd (x: string, y: string): void; Invoke (x: any, y: any): void;}"is not assignable to type "Point".
Property" myAdd" is private in type "Point" but not in type" {x: number; y: number; myAdd (x: string, y: string): void; Invoke (x: any, y: any): void;}".

does a class with a private property/function can only declare objects with a constructor?

Mar.23,2021
Menu