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

More specific type definitions for addJob #718

Closed
nathanbabcock opened this issue Mar 5, 2023 · 0 comments · Fixed by #719
Closed

More specific type definitions for addJob #718

nathanbabcock opened this issue Mar 5, 2023 · 0 comments · Fixed by #719

Comments

@nathanbabcock
Copy link
Contributor

nathanbabcock commented Mar 5, 2023

The current type definition for addJob is as follows:

addJob(action: string, ...args: any[]): Promise<ConfigResult | RecognizeResult | DetectResult>

Instead of using any arguments and a mixed return type, we could specify valid values for action and pair them with the expected argument types in each case.

Proposed implementation:

addJob(action: 'recognize', ...args: Parameters<Worker['recognize']>): Promise<RecognizeResult>
addJob(action: 'detect', ...args: Parameters<Worker['detect']>): Promise<DetectResult>
addJob(action: 'setParameters', ...args: Parameters<Worker['setParameters']>): Promise<ConfigResult>

The main benefit is in better Intellisense/autocomplete hints when using the API. Specific options are suggested to the user, instead of an opaque string type forcing them to refer to the documentation.

Here's an example of autocomplete in action, after adding the three more specific type definitions:

tesseract-add-job-intellisense

I will link a PR with this code in case it's something the maintainers would consider integrating. It is a type-only change that doesn't affect any functionality, and is backwards-compatible with the current type definitions (being just a more narrow version of these).

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

Successfully merging a pull request may close this issue.

1 participant