Skip to content

fix: correct return type of the options-only factory overload in random/streams/triangular#12565

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-streams-triangular-factory-return-type
Draft

fix: correct return type of the options-only factory overload in random/streams/triangular#12565
Planeshifter wants to merge 1 commit into
developfrom
philipp/random-streams-triangular-factory-return-type

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • corrects the return type of the options-only factory overload in random/streams/triangular.

The function returned by the options-only RandomStream.factory( options? ) overload creates streams generating pseudorandom numbers drawn from a triangular distribution, which is parameterized by the minimum support a, the maximum support b, and the mode c. The returned function therefore accepts three arguments, but the declared type listed only a and b:

factory( options?: Options ): ( a: number, b: number ) => RandomStream;          // before
factory( options?: Options ): ( a: number, b: number, c: number ) => RandomStream; // after

This matches the implementation (lib/main.js / lib/factory.js, whose returned creator takes ( a, b, c )) and the overload's own documented @example, which calls createStream( 2.0, 5.0, 4.0 ). The corresponding $ExpectType assertion in test.ts is aligned to use three arguments.

The existing type test continued to pass against the buggy type only because, in the positive-assertion block, the test variable is first assigned from the four-argument factory( a, b, c, options ) overload (whose return type is ( ...args: Array<any> ) => RandomStream), masking the arity of the options-only overload.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

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

This change was identified during a TypeScript-declaration audit of the @stdlib/random namespace.

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

A TypeScript-declaration audit surfaced this issue using Claude Code; the finding was independently verified against the implementation, and the proposed change was reviewed by myself before submitting.


@stdlib-js/reviewers

…ndom/streams/triangular

The function returned by the options-only `factory` overload creates
streams generating pseudorandom numbers drawn from a triangular
distribution, which is parameterized by the minimum support `a`, the
maximum support `b`, and the mode `c`. The returned function thus
accepts three arguments, but the declared type listed only `a` and
`b`. Correct the return type to `( a: number, b: number, c: number ) =>
RandomStream` to match the implementation and the documented example,
and align the corresponding type test.
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
random/streams/triangular $\color{green}838/838$
$\color{green}+100.00\%$
$\color{green}107/107$
$\color{green}+100.00\%$
$\color{green}15/15$
$\color{green}+100.00\%$
$\color{green}838/838$
$\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