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

[OV JS] Add TS definition for AnyMap #26711

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

almilosz
Copy link
Contributor

@almilosz almilosz commented Sep 20, 2024

Details:

  • Add definition of OVAny to addon.ts to encapsulate the concept of ov::Any from C++ API in a way that's clear and can be easily updated if the underlying C++ type changes. Improved readability and maintainability.
    -- 'OVAny' corresponds to Python API OVAny
  • In future updates to Node.js API, the OVAny type is expected to be enhanced with additional functionality.
  • Missed linter changes to core.test.js due to upstream merges

Tickets:

@almilosz almilosz requested a review from a team as a code owner September 20, 2024 10:47
@github-actions github-actions bot added the category: JS API OpenVino JS API Bindings label Sep 20, 2024
@@ -21,6 +21,12 @@ type elementTypeString =
| 'f32'
| 'string';

type Any = string | number | boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to choose different name, because Any crosses with any in TypeScript definition.
It can be longer, but cleaner, for example: AllowedPropertyType, ConfigPropertyType, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR description and I think the best name will be OVAny

Comment on lines 26 to 28
type AnyMap = {
[propertyName: string]: Any;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type AnyMap = {
[propertyName: string]: Any;
};
type AnyMap = Record<string, *AnyNewName*>;

https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, propose to replace AnyMap name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just explicitly add Record type in the place, where it uses.
Because our goal not to map values between C++ and JS sides, we should help developers by giving hints.
For AnyMap it looks like:
{EB9E1A7E-3DC9-4295-9DA8-AA946545726F}

If specify inline, it will give clearer hint:
{8E82A6E1-0CB1-40B9-BD71-A255B95FA5E7}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed definition of AnyMap. Agree that built-in Record type is a simpler way to represent a map of string keys to OVAny values and provides better hints.

@vishniakov-nikolai vishniakov-nikolai added this to the 2024.5 milestone Sep 26, 2024
@almilosz almilosz added this pull request to the merge queue Oct 2, 2024
Merged via the queue into openvinotoolkit:master with commit 32aaa2f Oct 2, 2024
153 checks passed
@almilosz almilosz deleted the almilosz/ts-anymap branch October 2, 2024 11:00
pkowalc1 pushed a commit to pkowalc1/openvino that referenced this pull request Oct 9, 2024
### Details:
- Add definition of `OVAny` to `addon.ts` to encapsulate the concept of
[ov::Any](https://docs.openvino.ai/2024/api/c_cpp_api/classov_1_1_any.html)
from C++ API in a way that's clear and can be easily updated if the
underlying C++ type changes. Improved readability and maintainability.
-- 'OVAny' corresponds to Python API
[OVAny](https://docs.openvino.ai/2024/api/ie_python_api/_autosummary/openvino.OVAny.html)
- In future updates to Node.js API, the OVAny type is expected to be
enhanced with additional functionality.
 - Missed linter changes to `core.test.js` due to upstream merges

### Tickets:
 - [CVS-149319](https://jira.devtools.intel.com/browse/CVS-149319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: JS API OpenVino JS API Bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants