Jonathan Tuzman
Jonathan Tuzman

Reputation: 13298

Typescript error on afterCreate in miragejs

I have the following code for my factory, omitting some properties for brevity.

export const propsPlayerDetailFactory = Factory.extend({
  sportId: () => getFakeSportId(),
  playerId: i => `${i}`,
  playerName: () => faker.name.findName(),
  playerProps: [] as PropAdminActiveGridRecord[],
  afterCreate(player, server) {
    player.update({ playerProps: server.createList('playerProp', 15) });
  },
});

afterCreate gives a Typescript error, but does work properly when the error is ignored.

TS2322: Type '(player: any, server: any) => void' is not assignable to type 'void | ((n: number) => void)'.   Type '(player: any, server: any) => void' is not assignable to type '(n: number) => void'. propsPlayer.factory.ts(37, 3):

The expected type comes from property 'afterCreate' which is declared here on type 'WithFactoryMethods<{ sportId: string; playerId: string; playerName: string; playerProps: PropAdminActiveGridRecord[]; afterCreate: void; }>'

Has anyone had any luck with factory hooks and typescript?

Upvotes: 3

Views: 214

Answers (0)

Related Questions