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

refactor: improve type definitions for ndarray array #1392

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

prajwalkulkarni
Copy link
Contributor

Resolves #1088

Description

What is the purpose of this pull request?

This pull request:

  • Improves type definition of ndarray's array function.
  • Infers return type based on the passed dtype's value, else uses buffer arguments' type.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

@Planeshifter From my understanding, I'm assuming the type of buffer argument and the type of buffer property in options argument are the same? Please let me know if otherwise.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@prajwalkulkarni
Copy link
Contributor Author

@Planeshifter could you kindly review this PR?

@@ -164,7 +164,7 @@ interface ExtendedOptions extends Options {
* var v = arr.get( 0 );
* // returns [ 1, 2 ]
*/
declare function array<T = unknown>( options: OptionsWithShape | OptionsWithBuffer ): typedndarray<T>;
declare function array<T = unknown>( options: OptionsWithShape<T> | OptionsWithBuffer<T> ): typedndarray<typeof options['dtype'] extends undefined ? T : typeof options['dtype']>;
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I follow how the return type is supposed to work. Can you provide examples of what you believe to be expected behavior?

Copy link
Member

Choose a reason for hiding this comment

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

You should also add corresponding tests to docs/types/test.ts to confirm expected behavior. All our TypeScript declarations should have corresponding unit tests.

@@ -220,7 +220,7 @@ declare function array<T = unknown>( options: OptionsWithShape | OptionsWithBuff
* var v = arr.get( 0, 0 );
* // returns 1.0
*/
declare function array<T = unknown>( buffer: ArrayLike<any>, options?: ExtendedOptions ): typedndarray<T>;
declare function array<T = unknown>( buffer: ArrayLike<T>, options?: ExtendedOptions<T> ): typedndarray<T extends undefined ? ( typeof options extends { dtype: infer D } ? D : never ) : T >;
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as above.

@kgryte kgryte added TypeScript Issue involves or relates to TypeScript. Needs Changes Pull request which needs changes before being merged. labels Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Changes Pull request which needs changes before being merged. TypeScript Issue involves or relates to TypeScript.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: improve type declarations for @stdlib/ndarray/array
2 participants