Skip to content
Myr

test-types-compilation.ts

This file

Path

test/test-types-compilation.ts

43 lines · 968 bytes · TypeScript

Last changed by

Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4

History of this file

Take it

Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4

lines 1–43why, one step back
1/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
23import mitt from '..';45const emitter = mitt();67/*8 * Check that if on is provided a generic, it only accepts handlers of that type9 */10{11 const badHandler = (x: number) => {};12 const goodHandler = (x: string) => {};1314 // @ts-expect-error15 emitter.on<string>('foo', badHandler);16 emitter.on<string>('foo', goodHandler);17}1819/*20 * Check that if off is provided a generic, it only accepts handlers of that type21 */22{23 const badHandler = (x: number) => {};24 const goodHandler = (x: string) => {};2526 // @ts-expect-error27 emitter.off<string>('foo', badHandler);28 emitter.off<string>('foo', goodHandler);29}303132/*33 * Check that if emitt is provided a generic, it only accepts event data of that type34 */35{36 interface SomeEventData {37 name: string;38 }39 // @ts-expect-error40 emitter.emit<SomeEventData>('foo', 'NOT VALID');41 emitter.emit<SomeEventData>('foo', { name: 'jack' });42}43