poimsm
poimsm

Reputation: 31

A class as an interface in angular typescript

In a component he uses something like:

Method (Obj: MyClass) { .... }

It's a shorthand for Obj = new MyClass ?

And if in the constructor of MyClass there is an argument needed, this should be Obj = new MyClass (argument) ? and the Obj: MyClass, still works?

Upvotes: 0

Views: 85

Answers (1)

lealceldeiro
lealceldeiro

Reputation: 14958

It's a shorthand for Obj = new MyClass ?

No, it is not. It only specifies that Method receives an argument (Obj reference inside the method) of type MyClass. It means the argument passed to Method must be an instance of MyClass.

Example of correct usage of Method:

const ob = new MyClass(); // supose `MyClass` constructor does NOT requieres any argument
Method(ob);

Example of incorrect usage of Method:

Method();

Upvotes: 1

Related Questions