Skip to content

Type the std* generator transform chunk argument - #1247

Merged
sindresorhus merged 1 commit into
mainfrom
improve-generator-transform-chunk-type
Jul 3, 2026
Merged

sindresorhus merged 1 commit into
mainfrom
improve-generator-transform-chunk-type

Conversation

@sindresorhus

Copy link
Copy Markdown
Owner

The transform generator function's chunk argument was typed as unknown, which forcd users to annotate it as unknown and rejected a (line: string) => transform. Its type is now based on the transform's mode: string for line transforms, Uint8Array when binary: true, and unknown when objectMode: true.

A binary encoding ('buffer', 'hex', 'base64', etc.) also makes the chunk a Uint8Array, since the subprocess output is binary in that case.

Fixes #694

The `transform` generator function's `chunk` argument was typed as `unknown`, which forcd users to annotate it as `unknown` and rejected a `(line: string) =>` transform. Its type is now based on the transform's mode: `string` for line transforms, `Uint8Array` when `binary: true`, and `unknown` when `objectMode: true`.

A binary `encoding` (`'buffer'`, `'hex'`, `'base64'`, etc.) also makes the `chunk` a `Uint8Array`, since the subprocess output is binary in that case.

Fixes #694
@sindresorhus
sindresorhus merged commit 0a7b4f8 into main Jul 3, 2026
20 checks passed
@sindresorhus
sindresorhus deleted the improve-generator-transform-chunk-type branch July 3, 2026 23:43
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.

Improve type of the std*: AsyncGeneratorFunction option

1 participant