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.

This is a:

  • Bug Report

Which concerns:

  • flow-runtime

What is the current behaviour?

I have this function which accepts callback with specified argument type. The callback is usually async function.

function RequestQueue({ requestDone: (ctx: RequestContext) => any }) {
}
// somewhere else...
const requestDone = async (ctx: RequestContext) => {
    await doSomeAsyncStuff()
}
RequestQueue({ requestDone })

RuntimeTypeError: requestDone argument “ctx” must be: RequestContext Expected: (ctx: RequestContext) => any Actual: (ctx: RequestContext) => any


What is the expected behaviour?

I can imagine this is probably bleeding edge stuff, but wanted to record this in here for some future reference. It’s possible it this be actually solved with native support for async/await. With transpilation in place it’s probably impossible task.


Which package versions are you using?

NodeJS v6.10.1

"babel-plugin-flow-runtime": "^0.10.0",
"babel-plugin-syntax-flow": "^6.18.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-latest-minimal": "^1.1.2",
"babel-preset-stage-1": "^6.22.0",

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
phpnodecommented, Apr 1, 2017

@FredyC thanks for digging into this, I can now replicate using:


type Options = {wares: {}};
const wares = {}

function RequestQueue({ wares }: Options, requestDone: (ctx: RequestContext) => any) {
  console.log('yo');
}

const param = async (ctx: RequestContext) => {
  
}

export type RequestContext = {
	requestId: Cuid,
	payload: string|Object,
	meta: Object,
	state: ?Object,
	error: ?string,
};

const requestQueue = RequestQueue({ wares }, param);
0reactions
danielkczcommented, Apr 1, 2017

@phpnode Well this code as a whole indeed works, however once I split it into separate files (as in my original code) it explodes… Here is the gist of how I’ve split it: https://gist.github.com/FredyC/05e980406416cf64f481dc4f8cd677a3

It did not matter when I’ve separated types only to a file, it worked well there. But with 3-way separation it almost looks like that imported RequestContext is different in both files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly ...
Read more >
Async/await - The Modern JavaScript Tutorial
The async keyword before a function has two effects: ... The await keyword before a promise makes JavaScript wait until that promise settles,...
Read more >
JavaScript Async - W3Schools
The await keyword can only be used inside an async function. The await keyword makes the function pause the execution and wait for...
Read more >
Async/await - Wikipedia
In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to ...
Read more >
Async/Await Function in JavaScript - GeeksforGeeks
Await : Await function is used to wait for the promise. It could be used within the async block only. It makes the...
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