In structural typing case, the code example returns false not because of difference of type. It returns false, because you’re trying to compare two different objects. Try to to create two instances of Dog class, and then compare them to each other. You will still get false.
When you use typeof dog == typeof person you will get true.
Hello, World! I'm jzombie, a passionate software developer with a knack for problem-solving and a love for open-source. I believe in the power of code to change the world and make our lives easier.
should let you know if dog actually inherits the relevant class, and it still works even if you created extension classes for dogs, as each extension will still be a dog.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In structural typing case, the code example returns
false
not because of difference of type. It returns false, because you’re trying to compare two different objects. Try to to create two instances of Dog class, and then compare them to each other. You will still getfalse
.When you use
typeof dog == typeof person
you will gettrue
.Good point! Thanks for clarifying.
In JS / TS,
should let you know if dog actually inherits the relevant class, and it still works even if you created extension classes for dogs, as each extension will still be a dog.