-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
add types definitions that also support ember-concurrency-decorators #355
add types definitions that also support ember-concurrency-decorators #355
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a TypeScript user, so I don't have a very sophisticated understanding of TypeScript type definitions, so apologies for some fairly basic questions.
I also have some sort of broad questions:
- Could you provide some details on what's different here versus Add Type Definitions #319?
- Does it address feedback raised there?
- Are there TypeScript version considerations?
- Is there a way to test/validate these (something that could be thrown in CI)?
The latter would make this more likely to be merged.
restartable(): TaskDecorator; | ||
maxConcurrency(num: number): TaskDecorator; | ||
enqueue(): TaskDecorator; | ||
withTestWaiter(): PropertyDecorator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is defined by ember-test-waiters
. perhaps this should live there? (is that a possible thing?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe? but should https://github.com/bendemboski/ember-concurrency-test-waiter get pulled in to this addon since it's a useful tool to help in testing with tasks?
restartable(): TaskDecorator; | ||
maxConcurrency(num: number): TaskDecorator; | ||
enqueue(): TaskDecorator; | ||
withTestWaiter(): PropertyDecorator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same q
export enum TaskState { | ||
RUNNING = 'running', | ||
QUEUED = 'queued', | ||
IDLE = 'idle', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding based on some feedback in #319, is that we should not export this in a type definition, since there is no such enum available to import.
export enum TaskInstanceState { | ||
/** task instance was canceled before it started */ | ||
DROPPED = 'dopped', | ||
|
||
/** task instance was canceled before it could finish */ | ||
CANCELED = 'canceled', | ||
|
||
/** task instance ran to completion (even if an exception was thrown) */ | ||
FINISHED = 'finished', | ||
|
||
/** task instance is currently running (returns true even if is paused on a yielded promise) */ | ||
RUNNING = 'running', | ||
|
||
/** task instance hasn't begun running yet (usually because the task is using the `TaskProperty#enqueue` task modifier) */ | ||
WAITING = 'waiting', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same deal here, re: exporting of an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, these probably don't need to be exported -- this is mostly copy paste from long ago
}; | ||
|
||
export function task( | ||
generator: Function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a GeneratorFunction
(or w/e the TypeScript-equivalent type name is)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends on if any type inference could be gained from doing so, like how I'm getting inference with decorators
/** | ||
* The most recently started task instance. | ||
*/ | ||
readonly last: TaskInstance<PerformArgs, PerformReturn>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this (and the other last*
properties) can also be null
. Do these need to be denoted as nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! yes, you're absolutely right. (though is it null or undefined?)
the main difference is that I've added some generics that help with type inference with decorators (see screenshots in original comment)
nope, I need to look at that
no clue, I'm only using 3.7.x in my apps
yea - we could build this in to the repo with full ember apps that aren't the dummy app, and try to use all of the APIs and make sure there are no type errors? |
}; | ||
export function timeout(wait: number): Promise<void>; | ||
|
||
export function didCancel(error: Error): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be export function didCancel(reason: unknown): reason is Error;
. In a promise callback, I don't think you necessarily know the reject reason object is an Error
, and so if you require this parameter to be Error
TypeScript might not let you pass it.
Thanks so much for your work on this! However, we're closing this in favor of #357, which has been merged and will be part of 1.2.0 |
After initial review
Huge thanks to @buschtoens for the work done in #319
these types enable the following, given these helper functions:
we can have inferred types from ember-concurrency-decorators!