Hooks load method Typescript error on V8

The load method of hooks fields in smartAction displays a Typescript error as follow:

Package:

image
image

Do you have any ideas to fix that ?

Hey @guillaumejauffret :wave:

I would suggest you to remove the @types/forest-express-mongoose, as the forest-express-mongoose@8 embed its own types.

(If the type is still incorrect though, I would be happy to fix it :+1: )

Let me know if that helps

hey @jeffladiray not it does not. I still get this error message

It seems I must type the smartAction I import in the forest-expression-mongoose collection() method with SmartActionOptions

import { mySmartAction } from '../smart-actions/my-smart-action.ts'

collection('account', {
  actions: [
    mySmartAction
  ]
})

if I don’t, I get this Typescript error message:

The problem still remains on hooks load method when giving the SmartActionOptions type to my smart action:

export const mySmartAction: SmartActionOptions = {
  name: 'my smart action',
  ...,
  hooks: {
    load: ({ fields, record }) => {}
  }
}

@guillaumejauffret weird indeed.

Looking at the type definition:

  • hooks is an allowed value in SmartActionOptions, as SmartActionHooks (Here)
  • load is an allowed value in the SmartActionHooks (Here)

From the error I can see in your last message, property type seems to have an incorrect value (Allowed single, bulk or global).

Could you share here (Or as DM) your smart action definition so I can check what is happening on my end?

Thanks :pray:

Yes I share it to you in DM

As you can see in the SmartActionLoadHook interface, record does not exist

Ok my bad, I did not understand the issue correctly.

Did you recently migrate to v8?

According to the v8 breaking change documentation (here - last paragraph), we do not provide the record to the hook function anymore (So the matching type seems to be correct).

1 Like

Ok I had not seen this update sorry.

However @jeffladiray ,

your doc does not seems to be very fresh.
Here you can see how a hook change function is written in your doc

image

but here is the type definition:

export interface SmartActionChangeHook {
  (context: { fields: SmartActionChangeHookField[], changedField: SmartActionChangeHookField, request: SmartActionChangeHookRequest }): SmartActionChangeHookField[] | Promise<SmartActionChangeHookField[]>
}

Indeed, I scratched my head understanding the issue as well. The documentation isn’t clear since it is the very last paragraph + all the examples above are not “good” example to explain the migration.

I’ll do a feedback to the team and update these examples accordingly. Thanks for reporting this :pray:

1 Like