diff --git a/index.d.ts b/index.d.ts index b7c1df1..6ccd2aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,12 @@ -import { Task, task, taskGroup } from 'ember-concurrency'; +import { + Task, + TaskInstance, + EncapsulatedTask, + EncapsulatedTaskProperty, + EncapsulatedTaskState, + task, + taskGroup, +} from 'ember-concurrency'; declare module 'ember-concurrency' { export type AsyncTaskFunction = (...args: Args) => Promise; @@ -9,21 +17,40 @@ declare module 'ember-concurrency' { export type AsyncTaskFunctionReturnType> = T extends (...args: any[]) => Promise ? R : unknown; + export type TaskForAsyncTaskFunction> = + Task, AsyncTaskFunctionArgs>; + + export type TaskInstanceForAsyncTaskFunction> = + TaskInstance>; + export interface AsyncEncapsulatedTaskDescriptor { perform(...args: Args): Promise; } export type AsyncEncapsulatedTaskDescriptorArgs> = - T extends (...args: infer A) => Promise ? A : []; + T extends { perform(...args: infer A): Promise } ? A : []; export type AsyncEncapsulatedTaskDescriptorReturnType> = - T extends (...args: any[]) => Promise ? R : unknown; + T extends { perform(...args: any[]): Promise } ? R : unknown; + + export type AsyncEncapsulatedTaskState = EncapsulatedTaskState; + + export type TaskForAsyncEncapsulatedTaskDescriptor> = + EncapsulatedTask< + AsyncEncapsulatedTaskDescriptorReturnType, + AsyncEncapsulatedTaskDescriptorArgs, + AsyncEncapsulatedTaskState + >; + + export type TaskInstanceForAsyncEncapsulatedTaskDescriptor> = + TaskInstance> & AsyncEncapsulatedTaskDescriptorArgs; function task>(taskFn: T): TaskProperty, AsyncTaskFunctionArgs>; function task>(taskFn: T): - TaskProperty, AsyncEncapsulatedTaskDescriptorArgs>; - - function taskGroup>(taskFn: T): - TaskGroup>; + EncapsulatedTaskProperty< + AsyncEncapsulatedTaskDescriptorReturnType, + AsyncEncapsulatedTaskDescriptorArgs, + AsyncEncapsulatedTaskState + >; } diff --git a/package.json b/package.json index de9c54b..d394cf7 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,9 @@ "ember-cli-babel-plugin-helpers": "^1.1.0", "ember-cli-htmlbars": "^4.3.1" }, + "peerDependencies": { + "ember-concurrency": "^1.2.1" + }, "devDependencies": { "@babel/core": "^7.10.2", "@babel/plugin-syntax-class-properties": "^7.10.1", @@ -49,7 +52,7 @@ "ember-cli-inject-live-reload": "^2.0.2", "ember-cli-sri": "^2.1.1", "ember-cli-uglify": "^3.0.0", - "ember-concurrency": "^1.2.0", + "ember-concurrency": "^1.2.1", "ember-concurrency-decorators": "^2.0.0", "ember-disable-prototype-extensions": "^1.1.3", "ember-export-application-global": "^2.0.1", diff --git a/yarn.lock b/yarn.lock index dca59fc..94249ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5113,10 +5113,10 @@ ember-concurrency-decorators@^2.0.0: ember-cli-htmlbars "^4.3.1" ember-cli-typescript "^3.1.4" -ember-concurrency@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/ember-concurrency/-/ember-concurrency-1.2.0.tgz#f8d09ff035ba7652f01de198b9e16424ef2b8522" - integrity sha512-XEKleKlcJQOTbMHEbEtIYF/VXSJDVB8H3pRFY5qmGqGujvpLaJY0GCQ6xtnTDdmSDkBO77FJ9o36GL7iwyqn6g== +ember-concurrency@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ember-concurrency/-/ember-concurrency-1.2.1.tgz#54fb234579638c5c43d4153a4e14567fe2b2e325" + integrity sha512-6zlK3BndPPZlSVWq6xBohwobpDKrI58nMMDfD8OqjoeBwnaznuyVHJqDZ46NRJrvSqYX6R96XBBVpDGCCcbK+w== dependencies: ember-cli-babel "^7.7.3" ember-compatibility-helpers "^1.2.0"