Skip to content
Myr

test-types-compilation.ts

This file

Path

test/test-types-compilation.ts

78 lines · 1.7 KiB · TypeScript

Last changed by

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

History of this file

Take it

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

lines 1–4why, one step back
1/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
23import mitt from '..';4

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 5–7why, one step back
5interface SomeEventData {
6 name: string;7}

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

line 8why, one step back
8

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 9–21why, one step back
9const 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) => {};21

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

line 22why, one step back
22/*

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

line 23why, one step back
23 * Check that 'on' args are inferred correctly

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

lines 24–25why, one step back
24 */
25{

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 26–28why, one step back
26 // @ts-expect-error
27 emitter.on('foo', barHandler);28 emitter.on('foo', fooHandler);

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

line 29why, one step back
29

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

line 30why, one step back
30 emitter.on('bar', barHandler);

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

line 31why, one step back
31 // @ts-expect-error

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 32–38why, one step back
32 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 back
39}
4041/*

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

line 42why, one step back
42 * Check that 'off' args are inferred correctly

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

lines 43–44why, one step back
43 */
44{

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 45–47why, one step back
45 // @ts-expect-error
46 emitter.off('foo', barHandler);47 emitter.off('foo', fooHandler);

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

line 48why, one step back
48

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

line 49why, one step back
49 emitter.off('bar', barHandler);

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

line 50why, one step back
50 // @ts-expect-error

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 51–57why, one step back
51 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 back
58}
5960/*

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

line 61why, one step back
61 * Check that 'emit' args are inferred correctly

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

lines 62–63why, one step back
62 */
63{

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 64–66why, one step back
64 // @ts-expect-error
65 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 back
67

Merge branch 'master' into patch_123Jason Millerbefore adoption53eb689

lines 68–78why, one step back
68 // @ts-expect-error
69 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}