diff options
Diffstat (limited to 'types/events.ts')
-rw-r--r-- | types/events.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/types/events.ts b/types/events.ts new file mode 100644 index 0000000..91be5b4 --- /dev/null +++ b/types/events.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | /** | ||
2 | * Contract source: https://git.io/JfefG | ||
3 | * | ||
4 | * Feel free to let us know via PR, if you find something broken in this contract | ||
5 | * file. | ||
6 | */ | ||
7 | |||
8 | import User from '#app/Models/User' | ||
9 | |||
10 | declare module '@ioc:Adonis/Core/Event' { | ||
11 | /* | ||
12 | |-------------------------------------------------------------------------- | ||
13 | | Define typed events | ||
14 | |-------------------------------------------------------------------------- | ||
15 | | | ||
16 | | You can define types for events inside the following interface and | ||
17 | | AdonisJS will make sure that all listeners and emit calls adheres | ||
18 | | to the defined types. | ||
19 | | | ||
20 | | For example: | ||
21 | | | ||
22 | | interface EventsList { | ||
23 | | 'new:user': UserModel | ||
24 | | } | ||
25 | | | ||
26 | | Now calling `Event.emit('new:user')` will statically ensure that passed value is | ||
27 | | an instance of the the UserModel only. | ||
28 | | | ||
29 | */ | ||
30 | interface EventsList { | ||
31 | 'forgot:password': { user: User; token: string } | ||
32 | } | ||
33 | } | ||