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.

async arrow functions fail on target es2018

See original GitHub issue

Hey there I cannot seem to get async arrow functions of a class to work

    class LogClass {
      public error = async (_: string) => null;
      public warn = async (_: string) => null;
    }
    const fakeLogger = mock(LogClass);
    when(fakeLogger.error(anything())).thenResolve(null) // fakeLogger.error is not a function
    // nor does
    when(fakeLogger.warn(anything())).thenReturn(Promise.resolve(null)); //fakeLogger.warn is not a function

However

    class LogClass {
      public error = (_: string) => null;
      public async warn (_: string) { return null };
    }
    const fakeLogger = mock(LogClass);
    when(fakeLogger.error(anything())).thenReturn(null);
    when(fakeLogger.warn(anything())).thenResolve();

works. I would like it if I could use async arrow functions

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dice14ucommented, Mar 27, 2019

Figured out the difference in my tsconfig.json

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "es2016",
    "lib": ["esnext.asynciterable", "es7", "dom"]
  },
}

works

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "es2018",
    "lib": ["esnext.asynciterable", "es7", "dom"]
  },
}

fails

0reactions
dice14ucommented, Apr 2, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax for an async arrow function - javascript - Stack Overflow
Async arrow functions look like this: const foo = async () => { // do something }. Async arrow functions look like this...
Read more >
async arrow function expected a return value - You.com
The resulting return of .then() is a promise. Ie, its a "promise" that something will happen or fail. Theres no "real value" being...
Read more >
JavaScript (ES2015+) Enlightenment - Frontend Masters
"An Arrow Function does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, this, or new.target within...
Read more >
babel/plugin-transform-arrow-functions
@babel/plugin-transform-arrow-functions. NOTE: This plugin is included in @babel/preset-env. Example.
Read more >
Node.js ES2015/ES6, ES2016 and ES2017 support
Yes. Yes Yes. Yes Error. Error Error. Error Error. Error Error. Error function() function() function() function() function() function() function() function() function() function() function() function() function() function()...
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