3 ms·
I mostly disagree with you here. Checking for the existence of a key on an object is dirt cheap. Even if you happen to have a case where it is expensive, ther
by horsawlarway 6y ago
I mostly disagree with you here.
Checking for the existence of a key on an object is dirt cheap.
Even if you happen to have a case where it is expensive, there's absolutely nothing that says your typeguard has to take that approach.
I've seen some reasonably sane code that just checks that the 'Type' field of the object matches the expected value, and the 'Version' field is the right number. It's not going to catch all the possible errors there if someone breaks the api contract, but it's a lot better than a raw cast.