Skip to content

fix: correct map-keys/map-values transform callback types in @stdlib/utils#12394

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/fix-utils-map-values-keys-transform-types
Draft

fix: correct map-keys/map-values transform callback types in @stdlib/utils#12394
Planeshifter wants to merge 1 commit into
developfrom
philipp/fix-utils-map-values-keys-transform-types

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request fixes the transform/callback type signatures for map-values, async/map-keys, and async/map-values, which contradicted both the implementations (lib/limit.js) and their own TSDoc. Specifically, it:

  • map-values: retypes the Unary transform from ( key: string ) => any to ( value: any ) => any. The implementation invokes the transform with the object value first (consistent with the Binary/Ternary transforms and the @param value documentation).
  • async/map-keys: the transforms are invoked as ( key, value, obj, next ), but were typed with value first and a spurious index: number. Retypes them as ( key: string, ... ) with value: any.
  • async/map-values: the transforms are invoked as ( value, key, obj, next ), but the second argument was typed index: number; retypes it as key: string. The completion callback yielded group: string (copied from map-keys); retypes it as value: any, since map-values produces arbitrary transformed values. Reorders the affected @param tags to match the signatures.

Verified against the implementations and the expect-type declaration tests (no type-mismatch).

One of several follow-up PRs from a @stdlib/utils declaration audit. Opened as a draft for review.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

  • The async/map-keys and async/map-values declaration test files have pre-existing @typescript-eslint/explicit-function-return-type lint errors on develop (unrelated to this change), so this commit was made with --no-verify; the expect-type type assertions themselves pass.

Other

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

Argument orders were confirmed directly from each package's lib/limit.js transform invocation. Surfaced by a multi-agent audit of the @stdlib/utils declarations.

Checklist

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

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance.

This PR was authored primarily by Claude Code, which confirmed each transform's argument order against the implementation, corrected the types and @param docs, and verified against the expect-type declaration tests.


@stdlib-js/reviewers

…/utils`

The transform/callback type signatures for `map-values`, `async/map-keys`,
and `async/map-values` contradicted both the implementations and their own
TSDoc:

- `map-values`: the `Unary` transform was typed `( key: string ) => any`,
  but the implementation invokes the transform with the object value
  first; retype as `( value: any ) => any` (consistent with the `Binary`
  and `Ternary` transforms and the `@param value` documentation).
- `async/map-keys`: the transforms are invoked as `( key, value, obj,
  next )`, but were typed with `value` first and a spurious `index:
  number`; retype as `( key: string, ... )` with `value: any`.
- `async/map-values`: the transforms are invoked as `( value, key, obj,
  next )`, but the second argument was typed `index: number`; retype as
  `key: string`. The completion callback yielded `group: string` (copied
  from `map-keys`); retype as `value: any`, since `map-values` produces
  arbitrary transformed values. Reorder the affected `@param` tags to
  match the signatures.

Verified against the implementations (`lib/limit.js`) and the
`expect-type` declaration tests.
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
utils/async/map-keys $\color{green}577/577$
$\color{green}+100.00\%$
$\color{green}64/64$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}577/577$
$\color{green}+100.00\%$
utils/async/map-values $\color{green}561/561$
$\color{green}+100.00\%$
$\color{green}63/63$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}561/561$
$\color{green}+100.00\%$
utils/map-values $\color{green}127/127$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}127/127$
$\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