andywer / typed-emitter

🔩 Type-safe event emitter interface for TypeScript
MIT License
268 stars 24 forks source link

Not compatible with template literals #40

Open davidyuk opened 1 year ago

davidyuk commented 1 year ago
import TypedEmitter from 'typed-emitter';

interface TemplateLiteralEvents {
  error: (error: Error) => void,
  message: (body: string, from: string) => void
  [key: `test:${string}`]: () => void;
}

type Test = TypedEmitter<TemplateLiteralEvents>;

fails with

Type 'TemplateLiteralEvents' does not satisfy the constraint 'EventMap'. Index signature for type 'string' is missing in type 'TemplateLiteralEvents'.ts(2344)

I'm using typescript@4.9.5. Not sure how to support this, maybe this is a limitation of typescript.