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
chore(TS): update typescript definitions #309
Conversation
I was thinking about this, and I think that we should definitely do this. I realized that these typings only affect how to import types not how it ends up importing the library. :D |
@TylorS Yeah, I'm for it. What's the current status here? Do we just need to do another round of review before merging, or is there more work to be done? |
If any one is up for reviewing it, I think it's in good enough shape. |
Actually, immediately after posting that, I realized something. |
Updated to support Es6 and Es5 imports and exports |
Assuming it would help, I'm going to try to get time to review this tomorrow. One thing I noticed tonight is that the latest commit switched indentation from spaces to tabs. |
Hmmm that wasn't on purpose, but I don't know if that really matters? |
I think the only reason it matters is that the |
I don't have too much further to go on the review but need to call it a night. I'll get back to this as soon as I can. So far, I have thirteen comments, mostly useful. |
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.
Hi @TylorS, I hadn't looked at our type defs in depth before and did a full review. I'm sure there are things I mentioned that aren't specifically part of this PR, but I hope that is ultimately more helpful than annoying.
Thanks for putting these together.
|
||
export function multicast<A>(s: Stream<A>): Stream<A>; | ||
declare module "most" { | ||
type SeedValue<S, V> = { seed: S, value: V }; |
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.
Indentation should be two spaces for the sake of consistency.
(Already mentioned, just including it with the review)
export function periodic<A>(period: number, a?: A): Stream<A>; | ||
export function fromEvent(event: string, target: any, useCapture?: boolean): Stream<Event>; | ||
|
||
export function unfold<A, B, S>(f: (seed: S) => SeedValue<S, B|Promise<B>>, seed: S): Stream<B>; |
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.
The documentation for unfold
says the unfolding function may return a promise for a tuple, rather than a tuple with a promised value. If the documentation is correct, the declaration should be something like:
export function unfold<A, B, S>(f: (seed: S) => SeedValue<S, B>|Promise<SeedValue<S, B>>, seed: S): Stream<B>;
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.
Correct :D
|
||
// es5 does not have typings for this | ||
// use any to allow type-casting | ||
type Generator<A, B, C> = 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.
What is the purpose of the B
and C
type params for Generator<A, B, C>
?
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 don't know :)
export default ClockTimer; | ||
} | ||
|
||
declare module "most/lib/scheduler/ClockTimer" { |
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.
It's cool you're supporting use of both ES5 and ES6 modules. Thank you!
declare module "most/src/iterable" { | ||
// es5 doesn't have typings for an Iterable | ||
// use any to allow type-casting | ||
type Iterable = 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.
Should the "most"
declarations import Iterable
from "most/src/iterable"
or vice versa? It seems like we should not have two declarations, even if they are just any
for now.
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'm wondering if it's better to not include it and allow users to include them themselves like we do with Promise
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.
That seems reasonable to me.
constructor(run: (t: number, x: T, sink: Sink<T>) => any, value: T, sink: Sink<T>); | ||
static event<T>(x: T, sink: Sink<T>): PropagateTask<T>; | ||
static end<T>(x: T, sink: Sink<T>): PropagateTask<T>; | ||
static error(err: Error, sink: Sink<any>): PropagateTask<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 drop the type param and move to any
for static error
?
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 TypeScript is poor in handling this, but when you go to write anything with this you can never expect any type of value but an error to be propagated, however to satisfy interfaces you will have to write .event
and .end
on a Sink
and I felt it was poor to force any types there.
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.
Ah, that makes sense. Maybe we should add a short comment explaining why.
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.
Let's go with any
and add a comment about it.
import { Disposable, Sink } from 'most'; | ||
import SettableDisposable = require('most/src/disposable/SettableDisposable'); | ||
|
||
export function tryDispose<T> (t: number, disposable: Disposable<T>, sink: Sink<T>): Promise<T> | void; |
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.
It looks like the implementation can return a non-Promise value.
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.
👍
<A, B>(f: (a: A) => B, args: [A]): B; | ||
<A, B, C>(f: (a: A, b: B) => C, args: [A, B]): C; | ||
<A, B, C, D>(f: (a: A, b: B, c: C) => D, args: [A, B, C]): D; | ||
<A, B, C, D, E>(f: (a: A, b: B, c: C, d: D) => E, args: [A, B, C, D]): E; |
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 is used by combine
, and our def for that has one overload that allows for five arguments, but the largest we define for invoke
allows just four arguments. Maybe we should add an invoke
overload with five arguments.
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.
Well it is possible to n
number of arguments as the default
case of invoke
falls back to fn.apply(...)
type Iterable = any; | ||
|
||
export function isIterable(x: any): boolean; | ||
export function getIterator(x: any): Iterable; |
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.
The return type should be an Iterator type rather than Iterable.
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.
👍
add (x: T): void; | ||
remove (x: T): void; | ||
isEmpty(): boolean; | ||
dispose(): Promise<T>; |
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 doesn't seem quite right. The implementation can return a Promise with a resolved value of nothing
or an array.
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.
👍
Thanks for the very thorough review, @brandonpayton! |
Add typings for most/lib/disposable/* Add typings for most/lib/scheduler/* Add typings for most/lib/*.js Add typings for mmost/lib/sink/* Update exports to ES2015
ES6 imports are used from the ES6 source code in `most/src` ES5 imports are user as before from `most/lib`
Hi @TylorS, I'm sorry it's taken a while to respond to your updates. I took a look at the latest, and it looks good to me with the exception of the following:
Thanks! |
@TylorS @brandonpayton What's the current status here? Master is ahead by a good bit now, so just wondering what the next steps here need to be. Thanks! |
@briancavalier I believe we just need updates in response to these three items. |
Thanks @brandonpayton. I'll do my best to reply to each of those at their original comment site. |
Looking back at the 3 remaining items, I think we've covered them in mostjs/core. Personally, I'd like to focus on getting a 1.0 release of that, and then "fixing" the type definitions here by porting most.js to use mostjs/core and updating most.js type definitions in the process. How does that sound? |
I agree! |
Sounds good to me! |
With Thanks for all the hard work here @brandonpayton, the work we did here definitely did not go to waste. Much of it made it over to |
Add typings for most/lib/disposable/*
Add typings for most/lib/scheduler/*
Add typings for most/lib/.js
Add typings for mmost/lib/sink/
Update exports to ES2015