Skip to content

Allow transform to return a stream - #463

Open
cpruijsen wants to merge 1 commit into
isaacs:mainfrom
cpruijsen:fix/issue-462
Open

cpruijsen wants to merge 1 commit into
isaacs:mainfrom
cpruijsen:fix/issue-462

Conversation

@cpruijsen

Copy link
Copy Markdown

Summary

Add Minipass to the transform return type: ReadEntry | Minipass | null | undefined | false | 0 | '' (same union style as #459). Runtime unpack already pipes a truthy transform result (entry.pipe(tx); tx.pipe(stream)).

transform is documented as returning a stream or a falsey value. v7.5.12 narrowed the TypeScript return type from any to ReadEntry. #459 restored falsey returns (null | undefined | false | 0 | ''), but returning a MiniPass stream still type-errors.

MiniPass is what the README tells callers to return; unpack.ts on('data', (chunk: Buffer) => …) stays well-typed. Alternatives: revert the return type to any, or accept Node duplex streams (NodeJS.ReadWriteStream / stream.Duplex). #459 expanded the union to the documented values instead of restoring any. Happy to switch to a wider Node stream type or any if that is preferred. Node core Transform still type-errors after this change.

Fixes #462

Test plan

  • Issue reproduction (extract({ transform: () => new Minipass({ async: true }) })) type-errors on v7.5.22
  • Same assignment compiles after the union change
  • Type test fails without the source change and passes with it (test/transform-type-check.ts)
  • Returning the entry / undefined / false still typechecks (transform type error when falsy value returned #459)
  • npm test -- -c -t0: 21247/21247 assertions pass, including test/transform-type-check.ts and test/unpack.js

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.

transform type error when stream value returned

1 participant