You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So a footgun I recently discovered with #field in v is that as it turns out if v is not an object, then #field in v throws an error. While this is consistent with "str" in v, it makes writing a class check even less ergonomic:
It's rather easy to forget to include isObject(v) everytime one writes an SomeClass.isSomeClass method. (Further compounded by the fact one needs to implement isObject in every codebase that does such a check).
This is a great opportunity for class.hasInstance to avoid this issue if it doesn't throw for non-objects:
v && #x in v seems a bit simpler - it won't throw on non-nullish primitives, so you don't actually need the typeof check - but you're right you need some kind of check.
So a footgun I recently discovered with
#field in v
is that as it turns out ifv
is not an object, then#field in v
throws an error. While this is consistent with"str" in v
, it makes writing a class check even less ergonomic:It's rather easy to forget to include
isObject(v)
everytime one writes anSomeClass.isSomeClass
method. (Further compounded by the fact one needs to implementisObject
in every codebase that does such a check).This is a great opportunity for
class.hasInstance
to avoid this issue if it doesn't throw for non-objects:The text was updated successfully, but these errors were encountered: