Home > Back-end >  TypeScript Template Literals break generic constraints
TypeScript Template Literals break generic constraints

Time:11-19

I am trying to write a Sub-Pub class that supports events AND sub-events denoted by the following syntax:

publisher.on("message:general", ... ) // subscribe to all messages
publisher.on("message", ... ) // subscribe to messages in general

To do this, I am using TypeScript template literals.

The issue is that while it broadly works, it seems to break generic constraints. Am I doing something wrong?

Here is what it looks like so far:

showing auto-complete list between empty quotes as first argument to subscribeToSubEvent function and that it suggests all valid options

  • Related