-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String Literal types on es6 interfaces for [Symbol.toStringTag]? #19006
Comments
Relevant commits: |
There is actually no such thing as an es6 interface, interfaces are purely a type system feature and, as that system is structural, there is actually no need to declare that your class implements any interface at all. However, in this case, your class does not in fact implement the interface, structurally or otherwise, because the interface does indeed require that value for the tag. It sounds more like you want to extend map. Unfortunately that will only work reliably under |
@aluanhaddad yeah, I understand those things. sorry, if I wasn't clear or didn't use the correct nomenclature. I wanted to use the type system to ensure that the class I built implemented the I'm not sure what you mean by "does indeed require that value for the tag" because this is typescript type, not something enforced by es6 and it would be incorrect for my class to declare that it is actually a I tried to create an interface that extends map and provides a different value for interface MySpecialMap<Object, Object> extends Map<Object, Object> {
readonly [Symbol.toStringTag] = "MySpecialMap";
} yielding the same error:
If I declare that it's my class that extends
I don't understand what benefit TypeScript is imbuing to the javascript developer by using string literal types for I think (note: I am using |
we should revert #6361. we tried to be too clever with the |
PRs welcomed. |
This is also a problem for Bluebird: petkaantonov/bluebird#1421 The overly strict We are between a rock and a hard place here. If we implement |
TypeScript Version: 2.5.3
Code
Expected behavior:
Classes implementing an ES6 interface can declare a distinct value for
Symbol.toStringTag
.The goal of this property is to provide a distinct value, using a string literal type for the interface is overly specific.
Actual behavior:
The text was updated successfully, but these errors were encountered: