-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Hello,
I would like to ask if it would be possible to implement the "implements" operator for run-time returning true or false based on evaluation if object implements an interface.
I can imagine there will be a lot of edge cases but for simple class - implements statements it would be simply doable.
Lets take a look on the following example:
interface ICredentials {
username: string;
password: string;
}
class A implements ICredentials {
username: string;
password: string;
...
}
class B {
...
}
let a: A = new A();
let b: B = new B();
# true
console.log(A implements ICredentials);
console.log(a implements ICredentials);
# false
console.log(B implements ICredentials);
console.log(b implements ICredentials);
for such cases we need to write something like:
function implementsICredentials(obj: any): boolean {
return
obj.hasOwnProperty("username") &&
obj.hasOwnProperty("password");
}
It is quiet a lot of code to be written manually if we want to test multiple interfaces. I can imagine the compiler could generate such functions for us.
Thanks for response.
Regards,
Franta
Akiq2016
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created