Skip to content
Back to skills

Typescript Language

ASecurity

Model the event catalog as a map from event names to payloads, then derive both the event name and payload types from that map. A discriminant or distinct key prevents mismatched payloads: ```ts type EventMap = { userCreated: { readonly userId: string }; invoicePaid: { readonly invoiceId: string; readonly amountCents: number }; }; type EventName = keyof EventMap; type Listener<K extends EventName> = (payload: EventMap[K]) => void; export class EventBus { private readonly listeners: { [K in Ev...

  • 549 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 5, 2026
development

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill typescript-language --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Typescript Language?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Typescript Language
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-typescript-language-5daba104/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-typescript-language-5daba104)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Model the event catalog as a map from event names to payloads, then derive both the event name and payload types from that map. A discriminant or distinct key prevents mismatched payloads:

```ts
type EventMap = {
  userCreated: { readonly userId: string };
  invoicePaid: { readonly invoiceId: string; readonly amountCents: number };
};

type EventName = keyof EventMap;
type Listener<K extends EventName> = (payload: EventMap[K]) => void;

export class EventBus {
  private readonly listeners: {
    [K in EventName]?: Set<Listener<K>>;
  } = {};

  public on<K extends EventName>(
    event: K,
    listener: Listener<K>,
  ): () => void {
    const listeners = this.listeners[event] ?? new Set<Listener<K>>();
    this.listeners[event] = listeners;
    listeners.add(listener);
    return () => listeners.delete(listener);
  }

  public emit<K extends EventName>(event: K, payload: EventMap[K]): void {
    this.listeners[event]?.forEach((listener) => listener(payload));
  }
}

const bus = new EventBus();
bus.on("invoicePaid", ({ amountCents }) => console.log(amountCents));
bus.emit("invoicePaid", { invoiceId: "inv-1", amountCents: 2500 });
```

`emit("invoicePaid", { userId: "u-1" })` is rejected at compile time. Keep the catalog and callbacks free of `any`; use explicit parameters/returns and readonly payloads.

Files in this skill

  • eval-1.baseline.md785 B
  • eval-1.with-skill.md769 B
  • eval-2.baseline.md1.3 KB
  • eval-2.with-skill.md1.3 KB
  • eval-3.baseline.md888 B
  • eval-3.with-skill.md659 B
  • trigger-1.md129 B
  • trigger-2.md146 B
  • trigger-3.md86 B
  • trigger-4.md116 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…