test-types-compilation.ts
This file
Path
test/test-types-compilation.ts
78 lines · 1.7 KiB · TypeScript
Last changed by
Stronger typing (#114)iyegoroffbefore adoption8f439b8
History of this fileTake it
Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 1–4why, one step back1/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */23import mitt from '..';4Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 5–7why, one step back5interface SomeEventData {6 name: string;7}Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 8why, one step back8Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 9–21why, one step back9const emitter = mitt<{10 foo: string;11 someEvent: SomeEventData;12 bar?: number;13}>();1415const barHandler = (x?: number) => {};16const fooHandler = (x: string) => {};17const wildcardHandler = (18 _type: 'foo' | 'bar' | 'someEvent',19 _event: string | SomeEventData | number | undefined20) => {};21Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 22why, one step back22/*Stronger typing (#114)iyegoroffbefore adoption8f439b8
line 23why, one step back23 * Check that 'on' args are inferred correctlyAdd generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 24–25why, one step back24 */25{Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 26–28why, one step back26 // @ts-expect-error27 emitter.on('foo', barHandler);28 emitter.on('foo', fooHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 29why, one step back29Stronger typing (#114)iyegoroffbefore adoption8f439b8
line 30why, one step back30 emitter.on('bar', barHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 31why, one step back31 // @ts-expect-errorStronger typing (#114)iyegoroffbefore adoption8f439b8
lines 32–38why, one step back32 emitter.on('bar', fooHandler);3334 emitter.on('*', wildcardHandler);35 // fooHandler is ok, because ('foo' | 'bar' | 'someEvent') extends string36 emitter.on('*', fooHandler);37 // @ts-expect-error38 emitter.on('*', barHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 39–41why, one step back39}4041/*Stronger typing (#114)iyegoroffbefore adoption8f439b8
line 42why, one step back42 * Check that 'off' args are inferred correctlyAdd generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 43–44why, one step back43 */44{Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 45–47why, one step back45 // @ts-expect-error46 emitter.off('foo', barHandler);47 emitter.off('foo', fooHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 48why, one step back48Stronger typing (#114)iyegoroffbefore adoption8f439b8
line 49why, one step back49 emitter.off('bar', barHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 50why, one step back50 // @ts-expect-errorStronger typing (#114)iyegoroffbefore adoption8f439b8
lines 51–57why, one step back51 emitter.off('bar', fooHandler);5253 emitter.off('*', wildcardHandler);54 // fooHandler is ok, because ('foo' | 'bar' | 'someEvent') extends string55 emitter.off('*', fooHandler);56 // @ts-expect-error57 emitter.off('*', barHandler);Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 58–60why, one step back58}5960/*Stronger typing (#114)iyegoroffbefore adoption8f439b8
line 61why, one step back61 * Check that 'emit' args are inferred correctlyAdd generic types and update tests (#107)Jack Franklinbefore adoption5116df4
lines 62–63why, one step back62 */63{Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 64–66why, one step back64 // @ts-expect-error65 emitter.emit('someEvent', 'NOT VALID');66 emitter.emit('someEvent', { name: 'jack' });Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4
line 67why, one step back67Stronger typing (#114)iyegoroffbefore adoption8f439b8
lines 68–78why, one step back68 // @ts-expect-error69 emitter.emit('foo');70 // @ts-expect-error71 emitter.emit('foo', 1);72 emitter.emit('foo', 'string');7374 emitter.emit('bar');75 emitter.emit('bar', 1);76 // @ts-expect-error77 emitter.emit('bar', 'string');78}