Skip to content

fix(types): propagateTask; decouple value type from sink type #123

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

Merged
merged 2 commits into from
Sep 5, 2017

Conversation

axefrog
Copy link
Contributor

@axefrog axefrog commented Sep 2, 2017

Without this change, propagateTask can't be used to pass a wrapper object as the value, with the internal values then unwrapped by the task runner for delivery to the sink.

Copy link
Member

@Frikki Frikki left a comment

Choose a reason for hiding this comment

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

I think that you may correct in your assumption. However, I think that the library also needs TypeScript tests.

@TylorS
Copy link
Member

TylorS commented Sep 2, 2017

This looks good to me 👍

Copy link
Member

@briancavalier briancavalier left a comment

Choose a reason for hiding this comment

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

Thanks @axefrog. Question about B = A type constraint.

export function propagateTask<T>(run: PropagateTaskRun<T>, value: T): (sink: Sink<T>) => PropagateTask<T>;
export function propagateTask<T>(run: PropagateTaskRun<T>): (value: T, sink: Sink<T>) => PropagateTask<T>;
export function propagateTask<T>(run: PropagateTaskRun<T>): (value: T) => (sink: Sink<T>) => PropagateTask<T>;
export function propagateTask<A, B = A>(run: PropagateTaskRun<A, B>, value: A, sink: Sink<B>): PropagateTask<A, B>;
Copy link
Member

Choose a reason for hiding this comment

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

Can you help me understand this B = A constraint? If A and B are always the same type, then I'm not seeing how this is different from a single type parameter

Copy link
Member

Choose a reason for hiding this comment

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

It's a type default. So if you only supply one type propagateTask<number>(...) it will assume B is of type number. Otherwise propagateTask<number, string>(..) will set A to number and B to string. It actually makes this a non-breaking change afaik

Copy link
Contributor Author

@axefrog axefrog Sep 2, 2017

Choose a reason for hiding this comment

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

@TylorS is correct; it's not a constraint, but rather allows omission of the second type in favour of the specified default. In this case, it preserves the default expectation while allowing for variance when needed.

Copy link
Member

Choose a reason for hiding this comment

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

Ohhhhh, I thought it was a constraint! Thanks! I don't mind a breaking change, but it's pretty cool that this makes it backward compatible.

I don't think flow has a notion of a type default, but we should update the flow refs to match without a default. Could you include that in this PR as well, @axefrog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could... I'd need to disclaim that I have no familiarity with flow, so you'd need to double check that I've done it correctly.

Copy link
Member

Choose a reason for hiding this comment

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

No worries. We're happy to help/review/etc. The change should be basically equivalent here except that flow doesn't support default types (unless I've missed it, which is also possible!).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay. PR updated.

Copy link
Member

@briancavalier briancavalier left a comment

Choose a reason for hiding this comment

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

Nice work, @axefrog. Thanks!

@briancavalier briancavalier merged commit 41614e4 into mostjs:master Sep 5, 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.

4 participants