-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[task-manager] correct the return type of TaskManagerTaskExecutor #32557
Conversation
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
6da2292
to
6af7b7d
Compare
Subscribed to pull request
Generated by CodeMention |
@@ -86,13 +86,15 @@ export interface RegisteredTask extends TaskManagerTask {} | |||
/** | |||
* Type of task executor – a function that handles the task. | |||
*/ | |||
export type TaskManagerTaskExecutor<T = unknown> = (body: TaskManagerTaskBody<T>) => void; | |||
export type TaskManagerTaskExecutor<T = any> = (body: TaskManagerTaskBody<T>) => Promise<any>; |
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.
rather than Promise<any>
it may be better to have
export type TaskManagerTaskExecutor<T = unknown, R= unknown> = (body: TaskManagerTaskBody<T>) => Promise<R>;
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 was thinking about introducing an another generic, but if you look at the code, we already were casting the result to any
, and it would be a breaking change for all of the task manager users in the TS project, and since we are close to the stable SDK release I decided not to introduce breaking change that late in the process.
However, we might revisit it this in the future, and follow up with more strict typing.
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.
OK but I don't think it should break as you added a "default". The default can be any
as well to match your result.
FYI you already changed the default of the data type original from unknown to any.
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 talking about the typing which we apply for the returned result in the handling process, it was any
for few years already, and I have changed unknown
to match that:
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.
Ok ...
I was wondering why T=unknown
changed to T=any
?
Also
adding a typing after so it's <T=unknown,R=unknown>
would not break the type because Promise<R>
which resolves to R
would get matched with any
What it does allow you to do is for BackgroundFetch
as an example in a future API
BackgroundFetch.defineTask(task:TaskManagerExecutor<Record<string,unknown>, BackgroundFetchResult>)
So it's a specific strongly typed version of defineTask for BackgroundFetch.
I chose Record<string,unknown> because the data varies from APNS vs FCM as I have noted in
also would this be backported to 51? |
Why
Should fix:
How
Add missing
Promise
to theTaskManagerTaskExecutor
return type. We were already awaiting the response:expo/packages/expo-task-manager/src/TaskManager.ts
Line 264 in 6da2292
Test Plan
The package lints correctly. The docs changes have been reviewed by running app locally.
Preview