Skip to content

refactor: improve type definitions for ndarray array #1392

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/node_modules/@stdlib/ndarray/array/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Options {
/**
* Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']).
*/
submode?: Array<string>;
submode?: Array<Mode>;

/**
* Boolean indicating whether to copy source data to a new data buffer (default: false).
Expand Down Expand Up @@ -76,7 +76,7 @@ interface Options {
/**
* Interface describing function options.
*/
interface OptionsWithShape extends Options {
interface OptionsWithShape<T> extends Options {
/**
* Array shape.
*/
Expand All @@ -89,13 +89,13 @@ interface OptionsWithShape extends Options {
*
* - If provided along with a `buffer` argument, the argument takes precedence.
*/
buffer?: ArrayLike<any>;
buffer?: ArrayLike<T>;
}

/**
* Interface describing function options.
*/
interface OptionsWithBuffer extends Options {
interface OptionsWithBuffer<T> extends Options {
/**
* Array shape.
*/
Expand All @@ -108,13 +108,13 @@ interface OptionsWithBuffer extends Options {
*
* - If provided along with a `buffer` argument, the argument takes precedence.
*/
buffer: ArrayLike<any>;
buffer: ArrayLike<T>;
}

/**
* Interface describing function options.
*/
interface ExtendedOptions extends Options {
interface ExtendedOptions<T> extends Options {
/**
* Array shape.
*/
Expand All @@ -127,7 +127,7 @@ interface ExtendedOptions extends Options {
*
* - If provided along with a `buffer` argument, the argument takes precedence.
*/
buffer?: ArrayLike<any>;
buffer?: ArrayLike<T>;
}

/**
Expand Down Expand Up @@ -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.


/**
* Returns a multidimensional array.
Expand Down Expand Up @@ -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.



// EXPORTS //
Expand Down