getting inferences working with typescript pubsubber
I have a few pointers regarding your snippet.
Return type
Let's start with pubSubber function return type. It's very nice that typescript infers types, but it also a good way to make a mistake. The bad thing about it is that you can accidentally change the return type without knowing it. If you use this function somewhere in the app there is a chance that typescript will notify you about the change. But if you are creating a library and don't have tests, you will change the return type without any error.
Personally, I like the rule to always specify return type (unless using inline arrow functions). I even use the lint rule to enforce this.
Don't use any
Change any to unknown. In this case, maybe it doesn't matter at least at the moment, but in the future, you may change this code. With any you can do anything and typescript won't say anything. With unknown you can't do anything, unless you cast it or use type Type Guard
const subscribers = new Map&lt;keyof T, Set&lt;Subscriber&lt;any&gt;&gt;&gt;()

Don't use cast if possible
Let's look into this line.
const current = (subscribers.get(topic) || new Set()) as Set&lt;
  Subscriber&lt;T[R]&gt;
&gt;;

current real type is Set&lt;Subscriber&lt;any&gt;&gt;, but you cast it to Subscriber&lt;T[R]&gt;. But in this example, there is no point having cast at all, because even without it the code is correctly typed. This function implementation works with any type, so you can leave it as it is. As for the outer interface, it can be more strict.
const current = subscribers.get(topic) || new Set()
current.add(subscriber);
subscribers.set(topic, current);
return () =&gt; current.delete(subscriber);

Second example is a bit better:
const toCall = Array.from((subscribers.get(topic) || [])) as Subscriber&lt;T[R]&gt;[];
toCall.map((f) =&gt; f(data))

You already had one mistake because of this cast. Also, I don't see any reason to convert Set to the list. You can just loop the Set. And if you combine it with optional chaining, it will look like:
subscribers.get(topic)?.forEach(f =&gt; f(data));

Better typing
In the previous section, I mentioned casts. But removing casts in theory you lose some typings (adding also lose some typings, dilemma...). Let's try to have full correct typings without any cast. So to start with we need to change Map to Object. Map types do not allow relations between key and value (e. g.: a key must-have number value`).
Example of relation-based subscribers list:
const subscribers: {
  [P in keyof T]?: Set&lt;Subscriber&lt;T[P]&gt;&gt;
} = {}

Final solution
So the final solution can looks like:
type Subscriber&lt;R&gt; = (data: R) =&gt; void;
type BaseTopics = Record&lt;string, unknown&gt;

interface PubSubber&lt;T extends BaseTopics&gt; {
  subscribe: &lt;R extends keyof T&gt;(topic: R, subscriber: Subscriber&lt;T[R]&gt;) =&gt; () =&gt; void
  publish: &lt;R extends keyof T&gt;(topic: R, data: T[R]) =&gt; void
}

function pubSubber&lt;T extends BaseTopics&gt;(): PubSubber&lt;T&gt; {
  const subscribers: {
    [P in keyof T]?: Set&lt;Subscriber&lt;T[P]&gt;&gt;
  } = {}
  return {
    subscribe(topic, subscriber) {
      const current = subscribers[topic] || new Set();
      current.add(subscriber);
      subscribers[topic] = current;
      return () =&gt; current.delete(subscriber);
    },
    publish(topic, data) {
      subscribers[topic]?.forEach(f =&gt; f(data));
    },
  };
};