Answer the question
In order to leave comments, you need to log in
How to assign a type that implements an interface?
There is an interface
Interface MyInterface {
myMethod(): string;
}
let MyInstance;
myInstance
this is an instance of the class that implements MyInterface
. How can I do that? If you do this: let myInstance: MyInterface;
then all unnecessary properties will give a compilation error, because an object literal is used, for example like this:myInstance = {myMethod() {return ''}, a: 3} // property 'a' doesnt exist in MyInterface
let myInstance: {} extends MyInterface;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question