Extended standard types and Symbol.toStringTag
See original GitHub issueMight be a question more than a bug, but how would you expect this to react?
const type = require('type-detect');
class ExtendedArray extends Array {
get [Symbol.toStringTag]() {
return 'ExtendedArray';
}
}
console.log(type(new ExtendedArray())); //=> 'array'
My initial expectation was that I would receive back ExtendedArray
through the use of Symbol.toStringTag
, but the code returns array
, from here. Is this intended?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Symbol.toStringTag - JavaScript - MDN Web Docs
toStringTag well-known symbol is a string valued property that is used in the creation of the default string description of an object.
Read more >String Literal types on es6 interfaces for [Symbol.toStringTag]?
I tried to create an interface that extends map and provides a different value for toStringTag but this doesn't work. interface MySpecialMap< ...
Read more >Using JavaScript Symbol.toStringTag for objects types ...
toString() using Symbol.toStringTag , so to describe a type for our user object we can do the following: const user = { username:...
Read more >Understanding Symbol: Javascript's Newest Primitive Type
First of all, symbol is a built-in primitive type. And it's guaranteed to be unique. Symbols are often used to add unique property...
Read more >JS Symbol and Well-known symbols - Oleh Baranovskyi
The Symbol() function returns a value of type symbol, has static properties that expose several members of built-in objects, has static methods that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hm. Here’s the official spec for “Array exotic objects”.
I poked around at a couple options, one of which was this, kept me at about 24,000,000 ops/sec (using Node v6.0.0 for this, by the way):
This works too, but drops down to about 2,800,000 ops/sec for array literals on my machine:
I also tried dropping the
Array.isArray()
call entirely, and instead let it flow to theobjPrototype
section to see ifobjPrototype === Array.prototype
. That got me about 18,000,000 ops/sec.The first option above did allow me to drop through to the bottom
toString.call()
and receive backextendedarray
. Here’s what I got with a few quick checks:Trying to think if that would be sufficient, or if I’m missing a scenario…
Another side note – is it intended that the custom
toStringTag
returns are lowercase?imo
Symbo.toStringTag
should take priority and return “ExtendedArray”, which would make this a bug.@keithamus @lucasfcosta ?