Skip to content

Commit

Permalink
Error if event creator doesnt return an object
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Mar 15, 2021
1 parent d11c696 commit 92cf869
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ export type ModelEventsFrom<
TModel extends Model<any, any, any>
> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;

type EventCreator<
Self extends AnyFunction,
Return = ReturnType<Self>
> = Return extends object
? Return extends {
type: any;
}
? "An event creator can't return an object with a type property"
: Self
: 'An event creator must return an object';

type EventCreators<Self> = {
[K in keyof Self]: Self[K] extends AnyFunction
? ReturnType<Self[K]> extends { type: any }
? "You can't return a type property from an event creator"
: Self[K]
? EventCreator<Self[K]>
: 'An event creator must be a function';
};

Expand Down

0 comments on commit 92cf869

Please sign in to comment.