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

Strict typing for TaskFunction #1

Open
mstephen19 opened this issue Oct 4, 2022 · 4 comments
Open

Strict typing for TaskFunction #1

mstephen19 opened this issue Oct 4, 2022 · 4 comments
Assignees
Labels
feature New feature or request good first issue Good for newcomers

Comments

@mstephen19
Copy link
Owner

mstephen19 commented Oct 4, 2022

Currently, the type definition for TaskFunction looks like this:

type TaskFunction = (...args: any[]) => Awaitable<any>;

Though this works, it is problematic because only certain basic data types can be sent to a worker via posting a message. Because the type is any, it does not prevent runtime errors caused by passing in things like functions or random class instances into these functions and expecting it to work.

The TaskFunction type should only accept certain acceptable data types that workers can receive, along with functions like parent.sendMessage or messenger.sendMessage. It must be strict.

@mstephen19 mstephen19 added the feature New feature or request label Oct 4, 2022
@mstephen19 mstephen19 self-assigned this Oct 4, 2022
@mstephen19 mstephen19 added the good first issue Good for newcomers label Oct 25, 2022
@mstephen19
Copy link
Owner Author

@vladfrangu got any ideas on how this could be done?

@mstephen19 mstephen19 assigned vladfrangu and unassigned mstephen19 Dec 26, 2022
@mstephen19
Copy link
Owner Author

We can wait for const annotations with TypeScript 5.0 to finally implement this.

@mstephen19
Copy link
Owner Author

Still struggling with this.

@gahabeen
Copy link
Collaborator

@mstephen19 Would you mind sharing a minimal example of what you'd like to achieve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants