Conversation
|
|
||
| // allow pushing data back into stream | ||
| stream = prefixStream(stream) | ||
| const stream = prefixStream(source) |
There was a problem hiding this comment.
📝 Type checker would not allow overloading same var here because it's type is IncomingMessage which is different from PrefixPush.
67521f0 to
c0da7bd
Compare
| for await (const tasks of batch(source, size)) { | ||
| /** @type {Promise<{ok:true, value:T}|{ok:false, err:Error}>[]} */ | ||
| const things = tasks.map(p => { | ||
| return p().then(value => ({ ok: true, value }), err => ({ ok: false, err })) |
There was a problem hiding this comment.
📝 Type checker can refine union types as long as they share a common property unique per variant. That is why ok field was added. That way type checker can infer type of result in both branches of if (result.ok).
| return next | ||
| } catch (err) { | ||
| pending.reject(err) | ||
| throw err |
There was a problem hiding this comment.
📝 TS rightly points out that without throw here iterator did not comply with Iterator<T> interface because next() returns { done:boolean, value: T }|undefined (undefined is returned because catch was swallowing an error). Added throw here so it type checks & I think that is also what code supposed to do.
| /** @type {UnderlyingSource<T> & { _cancelled:boolean} } */ | ||
| const pump = { | ||
| _cancelled: false, | ||
| async start () { |
There was a problem hiding this comment.
From what I understand given coveralls report it seems to conclude that coverage has decreased because start here is never called. Seems like a wrong conclusion, because all this change does is moved ReadableStream parameter to pump variable so it's easier to type annotate.
I can awkward inline type annotation, or suppress TS error (which otherwise complains about unknown _cancelled field). But it seems like ignoring coverall here might be a best option.
There was a problem hiding this comment.
I changed it to do inline thing to workaround coveralls.
|
@achingbrain just putting this on your radar, in case you missed it |
achingbrain
left a comment
There was a problem hiding this comment.
This looks good, a few minor nits but nothing major.
Thanks for submitting it!
Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
This pull request does following:
npm run checkcommand that runs a type checker.npm run buildandnpm run build:typesscripts that generate.d.tsfiles indist.typesVersionsfield topackage.jsonso that programs that install these libraries will get types out of the box.it-multipart(error was swallowed).npmignorewhich doesn't ignorepackage/*/distdirectories so they are published with a package.This also cherry-picks #11 to overcome playwright-test issues