Skip to content

Error when calling throttle function from lodash inside MST flow #2008

Answered by coolsoftwaretyler
midrizi asked this question in Q&A
Discussion options

You must be logged in to vote

This looks like it might be the issue described in #1378, or related at least. I don't think it necessarily has to do with lodash, but rather with the TypeScript interaction with generators.

I was able to clear the error in your TS playground by changing your code to:

import { throttle } from 'lodash'
import {types, flow} from 'mobx-state-tree'


export const UserStoreModel = types
  .model('UserStore')
  .props({
    uid: types.maybe(types.string),
  })
  .actions(() => ({
    throttledFunc: throttle(async function() {
        return 'sample'
    })
  }))
  .actions((self) => ({
    afterCreate: flow(function* () {
        yield self.throttledFunc() as Promise<string>
    })
  }))

as any

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by midrizi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants