Open jcbhmr opened 1 year ago
My vote is to follow the existing known conventions and try to mirror the Node.js node:util
isSymbol()
and friends APIs and how they detect things. https://nodejs.org/api/util.html
In this case, for isSymbol()
, that means typeof x === "symbol"
instead of the current version that uses Symbol.toStringTag
If you want, you can just copy-paste code from https://github.com/nodefill/util/tree/main/src/types
Right now if you use something like a math library that defines a
Symbol
class for math operations and doisSymbol()
on it, there is a serious non-zero chance that it will return true! 😱This happens because
isSymbol()
relies onSymbol.toStringTag
viaObject#toString()
to "sniff" the type. There are other more robust ways for this particular type, though, and I think they should be used.Example:
Or, you could get fancier and do a branch check on the
.description
getter! If it throws, it's not a symbol.