Does anyone know the correct TS syntax for extracting the type of a class method indexed with a well-known Symbol
? Here are two incorrect methods:
type T = String[Symbol.toStringTag];
// 'Symbol' only refers to a type, but is being used as a namespace here.(2702)
// Exported type alias 'T' has or is using private name 'Symbol'.(4081)
type U = String[Symbol['toStringTag']];
// Property 'toStringTag' does not exist on type 'Symbol'.(2339)
Click here to play with the code
Non-well-known symbols are currently unsupported in TS 4.1 (Fix may be coming soon) but according to ES6 well-known symbols should be supported.
For more insights on resolving this issue, you can refer to this helpful thread on Stack Overflow.