fix: correct TypeScript types in top-level array declarations#12365
Draft
Planeshifter wants to merge 1 commit into
Draft
fix: correct TypeScript types in top-level array declarations#12365Planeshifter wants to merge 1 commit into
array declarations#12365Planeshifter wants to merge 1 commit into
Conversation
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
---
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request corrects TypeScript type-signature defects in three top-level
@stdlib/arraypackage declarations, surfaced by an audit of thearraynamespace declaration files:from-scalar: the explicit'bool'dtype overload typed itsvalueparameter asany. Narrowed it toboolean, matching the inferred-dtype boolean overload and thefull-likesibling. Because this makes the overload unifiable with the inferred-dtype boolean overload, a// eslint-disable-line @typescript-eslint/unified-signaturesdirective is added (the same approach already used inarray/filled-by), since the two overloads are intentionally kept in their respective explicit/inferred groups.to-json:typedarray2jsonaccepted onlyRealOrComplexTypedArray, excludingBooleanArray, even though the implementation, README, and the declaration's owndtypeunion all support boolean arrays. Broadened the parameter toRealOrComplexTypedArray | BooleanArray(matching thefilled-byandpoolsiblings).next-dtype: the table-returning catch-all overload was declared as( dtype?: DataType ): Table, accepting adtypeargument 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/arraynamespace; it contains only type-signature corrections.One note for reviewers: broadening
to-jsonto acceptBooleanArraycauses the empty-array literal[]to type-check (theBooleanArrayinterface extendsAccessorArrayLike, which an empty array literal structurally satisfies), so the now-invalidtypedarray2json( [] ); // $ExpectErrorassertion 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
$ExpectTypelinters.@stdlib-js/reviewers