Skip to content

String Literal types on es6 interfaces for [Symbol.toStringTag]? #19006

Closed
@chriseppstein

Description

@chriseppstein

TypeScript Version: 2.5.3

Code

class MySpecialMap implements Map<Object, Object> {
   private _map;
   readonly [Symbol.toStringTag] = "MySpecialmap";
   constructor() { this._map = new Map(); }
   // declare all other methods of Map methods with some unique behaviors that wrap calls to this._map. 
}

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:

src/MySpecialMap.ts(1,7): error TS2420: Class 'MySpecialMap' incorrectly implements interface 'Map<Object, Object>'.
  Types of property '[Symbol.toStringTag]' are incompatible.
    Type '"MySpecialMap"' is not assignable to type '"Map"'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions