diff options
| author | Jack Franklin <[email protected]> | 2020-07-15 15:31:43 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-15 10:31:43 -0400 |
| commit | 5116df46a020ae498eec6783cfe9147fc9add015 (patch) | |
| tree | 93be70d93df33d1d60c7c3e4cfed0ae408e272cb /test/types.ts | |
| parent | 244cac2aa3d6831774129d6dc4942465dcef8099 (diff) | |
Add generic types and update tests (#107)
* Add generic types and update tests
* Add generic types to `on`, `off` and `emit` to enable some nicer TS
usage if you specify what type you're expecting from the `EventData`.
* Move the tests to be TypeScript source. This will help catch errors in
the tests if there are any type errors.
* Create a new test to test the generic types and make sure they pass
and error when expected.
* Upgrade to Mocha 8.
* Did some tidying up of the package.json scripts.
* Tweak TS setup to validate tests
* Fix d.ts generation and tests
Co-authored-by: Jason Miller <[email protected]>
Diffstat (limited to 'test/types.ts')
| -rw-r--r-- | test/types.ts | 20 |
1 files changed, 0 insertions, 20 deletions
diff --git a/test/types.ts b/test/types.ts deleted file mode 100644 index 23334bb..0000000 --- a/test/types.ts +++ /dev/null @@ -1,20 +0,0 @@ -import mitt, { EventHandlerList, EventHandlerMap } from '..'; - -const events = mitt(); -function foo() {} -events.on('foo', foo); -events.emit('foo', 'hello'); - -// handler return type should be ignored: -events.on('foo', async e => e * 42); - -// event map type -const map = new Map<string, EventHandlerList>([ - ['foo', [foo]] -]); -const events2 = mitt(map); -events2.emit('foo', 'hello'); - -// event map type & iterables -const map2 : EventHandlerMap = new Map(Object.entries(({ foo: [foo] }))); -mitt(map2); |
