question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.await has wrong type?

See original GitHub issue

Summary

I think the TypeScript type for Most.await is problematic. Consider this code:

  return Most
    .periodic(queueSettings.WaitTimeSeconds / 1000)
    .map(() => pull(settings.queue, queueSettings))
    .await() // should be awaitPromises but TypeScript definition doesn't accept that yet...
    .concatMap((data: AWS.SQS.ReceiveMessageResult) =>
      Most.from(data.messages.map(process)),
    )
    .multicast()

Expected result

It should return a Stream<Change>.

Actual Result

It instead returns a Stream<{}>. This is because of await which has a return value of Stream<{}>.

Versions

  • most.js: <version> ^1.4.0

I will try to come back with a PR or failing that a simplified repro.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
gcanticommented, Jun 20, 2017

there’s no way in TS to express “this method can only be called on a this whose value type is Promise<B>

Maybe this can be helpful

declare class Stream<A> {
  map<B>(f: (a: A) => B): Stream<B>
  // you can define a type annotation for this
  await<B>(this: Stream<Promise<B>>): Stream<B>
  // etc...
}

new Stream<number>().await() // error
new Stream<Promise<number>>().await() // ok
new Stream<string>().map(s => Promise.resolve(s.length)).await() // ok
1reaction
briancavaliercommented, Aug 13, 2017

@jasonkuhrt this just landed in most 1.6.1. Thanks again for raising the issue, and thanks @gcanti for the solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task has a wrong return type - Stack Overflow
No Task in your Button Click event. Just async . It's an event handler. Returns nothing. – Jimi. Aug 26, 2018 at 9:07....
Read more >
Wrong type after await · Issue #44314 · microsoft/TypeScript
Intellisense (hovering over) on this.myProp (last line of the load-method) shows type "number". Expected behavior. Intellisense on this.
Read more >
C# Async void return type of event handler got warning/error
I understand the async should not use void as return type unless it is an event handler. But I have code snippet above,...
Read more >
async/await is the wrong abstraction - LogRocket Blog
Async/Await is literally syntatic sugar over generators which is the correct abstraction. This article is like complaining that array.push is ...
Read more >
Asynchronous programming: futures, async, await | Dart
This codelab teaches you how to write asynchronous code using futures and the async and await keywords. Using embedded DartPad editors, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found