-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
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 that you may correct in your assumption. However, I think that the library also needs TypeScript tests.
This looks good to me 👍 |
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 @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>; |
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 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
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 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
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.
@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.
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.
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?
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 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.
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.
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!).
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.
Sorry for the delay. PR updated.
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.
Nice work, @axefrog. Thanks!
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.