From de845fdbe0f9653ebf358e2c3568be5a224afa07 Mon Sep 17 00:00:00 2001 From: Jack <33615628+jwbth@users.noreply.github.com> Date: Sun, 4 Aug 2024 03:11:59 +0400 Subject: [PATCH] Fix example in README.md Using an interface to define events triggers a TypeScript error: > Type 'Events' does not satisfy the constraint 'EventMap'. > Index signature for type 'string' is missing in type 'Events'. This is due to a peculiar behavior of TypeScript compiler that only allows use of types in such curcumstances (see https://github.com/microsoft/TypeScript/issues/15300). So I replaced the interface with a type. (A type is actually already used in another example above.) [Test in TS playground](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgURMGMCmU4F84BmUEIcA5AM4xTADGMAtJgG6YB2jmaG2ZAUHwD0guAEYAdHAAimAsDaY4AQzZx5WKASW1FMABZL4AE0wVaNAEam4ATwgBXHC3YwK4oSIDKmeM45w2JRBrJQo4fUUAa0wbCgAaZTYjcL1MYCcADzBMekxksCUbABsIJSMw0LhmJSL7U3cYG2yUVg4wgF5EPjg4Wgg2BXoALjgAbWAjEaoaNgBzAF1uuCNgM37BmBHxybhp+QW+XAFhOAAmSQBhKExDRSVd6jpfbg1E-NCwiLgwa+ZgBwoRRsy1k8jycAARMhWq4IR5lGF0GE5FAqHBZuxsHRlFBZvZghx3H02GiuOhXp0FAB3FAvbAAHmhLgoAD4ABQASmOIgAzJIAKoUXSpSFknhQCEpRQUIKKKmFWwOMjJexCqVwa54opKHBQmGocnYSXyKgqHTuMUacRlIwAGVWWAUUDZZGJGzICTZEw5cHaLMQuC5luw4jFLrdORgHvISgstAYolOPLIXKAA) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c972baa..0025046 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,9 @@ npm install strict-event-emitter ```ts import { Emitter } from 'strict-event-emitter' -// 1. Define an interface that describes your events. +// 1. Define a type that describes your events. // Set event names as the keys, and their expected payloads as values. -interface Events { +type Events = { connect: [id: string] disconnect: [id: string] }