Skip to content

Commit

Permalink
update write/end types to comply with NodeJS.WritableStream
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 4, 2024
1 parent 7231d42 commit a333b49
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# chernge lerg

## 7.1

- Update the type definitions to be more easily extended in
classes that are compatible with the NodeJS.WritableStream type
in the latest versions of `@types/node`.

## 7.0

This is a big one, please read carefully before upgrading from
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"node": ">=16 || 14 >=14.17"
},
"tap": {
"typecheck": true,
"include": [
"test/*.ts"
]
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ export class Minipass<
chunk?: WType | (() => void),
encoding?: Minipass.Encoding | (() => void),
cb?: () => void
) {
): this {
if (typeof chunk === 'function') {
cb = chunk as () => void
chunk = undefined
Expand Down Expand Up @@ -1102,7 +1102,7 @@ export class Minipass<

[EMITDATA](data: RType) {
for (const p of this[PIPES]) {
if (p.dest.write(data) === false) this.pause()
if (p.dest.write(data as RType) === false) this.pause()
}
const ret = this[DISCARDED] ? false : super.emit('data', data)
this[MAYBE_EMIT_END]()
Expand Down
22 changes: 22 additions & 0 deletions test/writable-type-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Minipass } from '../src/index.js'

let tester: NodeJS.WritableStream
tester = new Minipass()
tester = new Minipass<Buffer>()
tester = new Minipass<Buffer | string>()
tester = new Minipass<Buffer, Minipass.ContiguousData>()
tester = new Minipass<string>({ encoding: 'hex' })
tester = new Minipass<string, Buffer | string>({ encoding: 'hex' })
tester = new Minipass<Buffer, string>()

// We expect this one to be an error, because the NodeJS.WritableStream
// does not allow objectMode streams, so it would be a problem to use an
// OM minipass in contexts where a NodeJS.WritableStream is expected.
//@ts-expect-error
tester = new Minipass<{ a: 1 }>({ objectMode: true })

// so the linter doesn't complain about unused variable
tester

import { pass } from 'tap'
pass(`just making sure TS doesn't complain`)

0 comments on commit a333b49

Please sign in to comment.