ava: Ava `test()` expression is not callable / has no call signatures

I ran npm ava init in a project and created a first test as per ava docs.

Immediately the vscode editor is giving me a typescript warning error.

This expression is not callable.
  Type 'typeof import("/Users/dc/dev/exiteer/xbot/server/node_modules/ava/index")' has no call signatures.

image

I did look if there were separate typings but there is a index.d.ts as part of the basic module that’s installed.

We’ll also need your AVA configuration (in package.json or ava.config.* configuration files) and how you’re invoking AVA. Share the installed AVA version (get it by running npx ava --version).

At this point i don’t have any config files for ava, the initial install didn’t seem to create.

FWIW this is a js file but I am leaving the typescript error checking running, i find it catches a lot of type errors even in plain JS files without type declarations.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@novemberborn export default test in a type definition .d.ts only works for ESM imports but export = test will work for both. Could we revisit the idea of using export = test? You can test this by creating the following type definition files and doing both import and require.

// test.js
module.exports = function (name) {
  return;
}
// test.d.ts
declare function test(name: string): void;
export default test; // this looks valid but does not work with VSCode for require.
// index.js
import test1 from './test';
const test2 = require('./test'); // The type is "import test2" instead of the function declaration above.

test1("a");
test2("b"); // This expression is not callable

Now if you replace export default test in the above example with export = test the types work as expected. The below video shows this in action.

https://user-images.githubusercontent.com/19195374/114308335-b65e2480-9aa0-11eb-8c9e-da374b376bc1.mp4

I also tested this with all plugins disabled in VSCode and it still happens. I also tried it with my TypeScript version set to typescript@latest.

const test = require('ava').default instead of const test = require('ava') fixes it!

If you’re referring to an individual project’s TypeScript configuration, I don’t think that is the issue because I didn’t even have a TypeScript config for the above example.

That’s a great clue 😄