Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Conversation

TylorS
Copy link
Collaborator

@TylorS TylorS commented Sep 1, 2016

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

@TylorS
Copy link
Collaborator Author

TylorS commented Sep 15, 2016

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

@briancavalier
Copy link
Member

@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?

@TylorS
Copy link
Collaborator Author

TylorS commented Sep 16, 2016

If any one is up for reviewing it, I think it's in good enough shape.

@TylorS
Copy link
Collaborator Author

TylorS commented Sep 16, 2016

Actually, immediately after posting that, I realized something. most/lib can be defined here as having commonjs modules, and (sadly duplicated) most/src can be defined here with ES modules

@TylorS
Copy link
Collaborator Author

TylorS commented Sep 16, 2016

Updated to support Es6 and Es5 imports and exports

@brandonpayton
Copy link
Contributor

brandonpayton commented Sep 23, 2016

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.

@TylorS
Copy link
Collaborator Author

TylorS commented Sep 23, 2016

Hmmm that wasn't on purpose, but I don't know if that really matters?

@briancavalier
Copy link
Member

I think the only reason it matters is that the src dir is using spaces. It'd be nice to be consistent.

@brandonpayton
Copy link
Contributor

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.

Copy link
Contributor

@brandonpayton brandonpayton left a 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 };
Copy link
Contributor

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>;
Copy link
Contributor

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>;

Copy link
Collaborator Author

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
Copy link
Contributor

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>?

Copy link
Collaborator Author

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" {
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Contributor

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>;
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Member

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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>;
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@briancavalier
Copy link
Member

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`
@brandonpayton
Copy link
Contributor

brandonpayton commented Nov 21, 2016

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:

  1. The ap definition still appears incorrect against the implementation. Comment here.
  2. Consider adding a comment explaining why constraints are loosened. Comment here.
  3. Update the Timer interface discussed here. Perhaps adding a simple Asap handle type would be sufficient.

Thanks!

@briancavalier
Copy link
Member

@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!

@brandonpayton
Copy link
Contributor

@briancavalier I believe we just need updates in response to these three items.

@briancavalier
Copy link
Member

Thanks @brandonpayton. I'll do my best to reply to each of those at their original comment site.

@briancavalier
Copy link
Member

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?

@TylorS
Copy link
Collaborator Author

TylorS commented Apr 20, 2017

I agree!

@brandonpayton
Copy link
Contributor

Sounds good to me!

@TylorS
Copy link
Collaborator Author

TylorS commented Nov 11, 2017

With @most/core v1 released now, I don't see a need to keep this PR open. Further issues with types will likely be better sent in that direction.

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 @most/* packages :)

@TylorS TylorS closed this Nov 11, 2017
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.

None yet

3 participants