Skip to content

Commit d978a74

Browse files
committed
src: Improve types for natives like String.
1 parent ba41aa2 commit d978a74

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

example/test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ class Test {
66

77
const m = new PubSub();
88

9-
m.subscribe(Test, (b) => {
10-
console.log(b);
9+
m.subscribe(Test, (t) => {
10+
console.log(t);
1111
});
1212

13+
m.subscribe(String, (s) => {
14+
console.log(s);
15+
});
16+
17+
m.publish("sdfg");
1318
m.publish(new Test());

pubsub.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export type Constructable<T> = { new (): T };
44
export class PubSub {
55
private subscribers = new Map<unknown, Subscriber<any>[]>();
66

7-
public subscribe<T>(subscriptable: Constructable<T>, cb: Subscriber<T>) {
7+
public subscribe<T extends Constructable<unknown>>(
8+
subscriptable: T,
9+
cb: Subscriber<InstanceType<T>>,
10+
) {
811
const subs = this.subscribers.get(subscriptable) ?? [];
912
subs.push(cb);
1013
this.subscribers.set(subscriptable, subs);

0 commit comments

Comments
 (0)