-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type definitions #47
Conversation
Updates the devDependency `rx@4` to `rxjs@5`. Closes gulpjs#41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demurgos I don't know much about these typings but I sent some questions/thoughts. They seem good. Do you know of anyone else you can ping that can review these at a higher level than me?
index.d.ts
Outdated
*/ | ||
import { ChildProcess } from "child_process"; | ||
import { EventEmitter } from "events"; | ||
import { Readable as ReadableStream } from "stream"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be Readable, Writeable or Transform/Duplex because we exhaust the stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be able to reference the base "Stream" instead? Not sure if it contains the indicators we use to check for stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had Stream
but wasn't sure if Writable streams were supported. Thanks for confirming that any Node stream is fine. I'll update it.
test/observables.js
Outdated
|
||
function success() { | ||
return Observable.empty(); | ||
} | ||
|
||
function successValue() { | ||
return Observable.return(42); | ||
return Observable.of(42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment that this was previously Observable.return
in case someone was using the docs as a reference for older Rx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe we should keep both dependencies (rx & rxjs) since 4.x is still published as rx??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rx
is only used for the tests so I don't think we need to keep both versions as dependencies but it's definitely valuable to add a comment and mention it in the documentation. I'll do it.
test/types/streams.ts
Outdated
import { Readable, Stream } from "stream"; | ||
|
||
function readableSuccess(): Readable { | ||
return undefined as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these returning undefined as any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These file are compiled but never run. I just needed to check that a function returning a Readable
is accepted.
I did not care about the implementation of the task (runtime behavior is tested in test/streams.js
). Using any
allows to bypass type-checking locally ("trust me, this function returns a Readable").
I wrote the body of the functions for other kinds of objects because they are one-liners and it is more helpful to visualize a concrete example. In the case of streams, the boiler plate was slightly higher so I just used a dummy body.
I'll replace it with return new Stream();
instead of replicating what's in the unit-tests.
Thanks for checking. Before Typescript 2 and the existence of @unional @blakeembrey
|
It is also related to this: microsoft/TypeScript#12400
Not sure what you mean, global augmentation?
I assume its used in a callback (can't find that in your PR from skimming)? AFAIK, there is no way to prevent that. 🌷 |
Great! I'm still waiting for variadic types but the issue you linked should help with this case. Glad to see it got scheduled.
Sorry I was still calling them "ambient declarations", but yes: this is what I had in mind.
Yes, it was used in callbacks.
Passing I don't think it is supported currently, but I had an idea like this: interface AsyncTask {
(done: VoidCallback): void;
length: 1;
} This would add the constraint that functions have to have exactly one parameter. |
- Document support for RxJS 4 and 5 - Accept `Stream` as a return value instead of `Readable` - Remove dummy body in stream tests. - Reword some comments. Closes gulpjs#41
Most of the comments were addressed: would it be possible to merge and publish it (semver feature)? Regarding my questions in this thread: it's safer to keep global definitions (Node) as devDependencies and the issue to unify |
@demurgos I've reviewed everything and it seems to make sense with my minimal knowledge (thanks for all the docs). I'll get this published. |
@demurgos whoops, the index.d.ts wasn't added to "files" in the package.json so I publishing as 1.3.1 |
This also updates the devDependency
rx@4
torxjs@5
because it bundles its own types.This is a semver minor update (feature).
Two comments regarding these types:
null
. This is undocumented and untested but true according to the code. It would be better to update the doc and tests to reflect this since it's already implemented this way.done
callback to return multiple values are rejected by the type checker, and the interface of callbacks allows unsound callback functions: the result can be assumed to always exist, despite the possibility of error. This matches Node types. I'd prefer to have stricter interfaces but ended up using Node's style for usability. I am not yet sure if it's the right thing to do.Closes #41
/cc @BurtHarris @phated