Skip to content

fix: correct TypeScript types in top-level array declarations#12365

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/fix-array-ts-types
Draft

fix: correct TypeScript types in top-level array declarations#12365
Planeshifter wants to merge 1 commit into
developfrom
philipp/fix-array-ts-types

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

This pull request corrects TypeScript type-signature defects in three top-level @stdlib/array package declarations, surfaced by an audit of the array namespace declaration files:

  • from-scalar: the explicit 'bool' dtype overload typed its value parameter as any. Narrowed it to boolean, matching the inferred-dtype boolean overload and the full-like sibling. Because this makes the overload unifiable with the inferred-dtype boolean overload, a // eslint-disable-line @typescript-eslint/unified-signatures directive is added (the same approach already used in array/filled-by), since the two overloads are intentionally kept in their respective explicit/inferred groups.
  • to-json: typedarray2json accepted only RealOrComplexTypedArray, excluding BooleanArray, even though the implementation, README, and the declaration's own dtype union all support boolean arrays. Broadened the parameter to RealOrComplexTypedArray | BooleanArray (matching the filled-by and pool siblings).
  • next-dtype: the table-returning catch-all overload was declared as ( dtype?: DataType ): Table, accepting a dtype argument even though the implementation returns a table only when invoked with no arguments. Made the overload parameterless and corrected its duplicated/contradictory examples.

Related Issues

None.

Questions

No.

Other

This is one of a series of PRs addressing findings from a TypeScript-declaration audit of the @stdlib/array namespace; it contains only type-signature corrections.

One note for reviewers: broadening to-json to accept BooleanArray causes the empty-array literal [] to type-check (the BooleanArray interface extends AccessorArrayLike, which an empty array literal structurally satisfies), so the now-invalid typedarray2json( [] ); // $ExpectError assertion was removed from the type test. The remaining negative assertions (string, number, boolean, {}, null, undefined) are retained.

Checklist

AI Assistance

  • Yes

  • No

  • Code generation (e.g., when writing an implementation or fixing a bug)

  • Test/benchmark generation

  • Documentation (including examples)

  • Research and understanding

Disclosure

The issues fixed here were identified by a multi-agent audit run with Claude Code, and the changes were drafted by Claude Code under my direction and review. Each fix was verified locally against the repository's TypeScript declaration doctest and $ExpectType linters.


@stdlib-js/reviewers

Correct three type-signature defects surfaced by an audit of the
`array` namespace declarations:

-   `from-scalar`: the explicit `'bool'` dtype overload typed `value`
    as `any`; narrow it to `boolean` to match the inferred-dtype
    boolean overload and the `full-like` sibling.
-   `to-json`: `typedarray2json` excluded `BooleanArray`, which the
    implementation, README, and the declaration's own `dtype` union
    support; broaden the parameter to accept it.
-   `next-dtype`: the table-returning catch-all overload accepted a
    `dtype` argument despite the implementation returning a table
    only when invoked without arguments; make it parameterless.

Also update the affected examples and type tests.

Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
array/from-scalar $\color{green}158/158$
$\color{green}+100.00\%$
$\color{green}19/19$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}158/158$
$\color{green}+100.00\%$
array/next-dtype $\color{green}117/117$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}117/117$
$\color{green}+100.00\%$
array/to-json $\color{green}255/255$
$\color{green}+100.00\%$
$\color{green}24/24$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}255/255$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

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 this pull request may close these issues.

2 participants