Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript question for creating custom task modifiers #513

Open
LanceStasinski opened this issue Feb 14, 2023 · 1 comment
Open

Typescript question for creating custom task modifiers #513

LanceStasinski opened this issue Feb 14, 2023 · 1 comment

Comments

@LanceStasinski
Copy link

Hello, I've added a custom task modifier to restore the functionality of waitFor from @ember/test-waiters. Do you have any suggestions for improving the types for this custom modifier? Thank you in advance!

import { TaskFactory, registerModifier } from 'ember-concurrency'
import { waitFor } from '@ember/test-waiters'

declare module 'ember-concurrency' {
  interface TaskFactory<T, Args> {
    taskDefinition: Function & TaskDefinition<T, Args>
  }
}

function waitForTask<T, Args extends unknown[]>(taskFactory: TaskFactory<T, Args>, option: boolean) {
  if (!option) {
    return
  }

  const { taskDefinition } = taskFactory
  const waitForTaskDefinition = waitFor(function* (this: unknown, ...args: Args) {
    yield* taskDefinition.apply(this, args)
  })

  taskFactory.setTaskDefinition(waitForTaskDefinition)
}

export function initialize() {
  registerModifier('waitFor', waitForTask)
}

export default {
  initialize,
}
@SergeAstapov
Copy link

that will be great to bring this functionality back.
I wonder if it's worth to built into ember-concurrency itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants