-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Ava test()
expression is not callable / has no call signatures
#2539
Comments
test()
expression is not callable / has no call signatures
My guess is that this is a mis-match between the type definition using In #2435 I'm switching to a CJS export, but that work's stalled. It'd be a breaking change I think. |
I think it might be cos I was trying to switch over from Jest. I'm not clear exactly but i think Jest does various things to your env... injecting globals somehow? This was for a project based on a boilerplate I used. there's a perhaps a part at the end of the
|
Oh right I thought this was some type output from VSCode but you're saying it's from ESLint? |
Correct. See: sindresorhus/memoize#31 |
The message is within VS code, but i think from the typescript compile checker ts2349 shows up this issue in the TS repo and |
|
@feljx's solution does seem to work. This should be the documented way of using AVA or we should find a way to fix this type definition issue. I have found a solution to this. If we replace the following line in the // Replace this
export default test;
// With this
export = test; However, I'm unaware of how AVA's type definition file was made — i.e. automated or hand-made. If it was hand-made, I or someone else can make a PR for this, which should be simple given it is only a one-line change. If the generation of |
AVA 4 (prereleases available) now ships with an ESM entrypoint that uses |
@novemberborn // 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 index.js.-.test.WSL_.Ubuntu.-.Visual.Studio.Code.2021-04-11.10-23-00.mp4I also tested this with all plugins disabled in VSCode and it still happens. I also tried it with my TypeScript version set to |
And @novemberborn you can have different types for different module systems I believe. Each entry point needs its own |
OK, I'll have a play with your examples and AVA itself. It's not something I've run into myself. Do you know if it's somehow related to the TypeScript config?
AVA 4 uses Node.js exports mapping, so it's transparent to the consumer. Use |
@novemberborn 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. It could be related to how VSCode integrates with TypeScript for type checking related features perhaps, however, if that is the case, creating a fix in this repository would still benefit VSCode users while the upstream issue is being fixed. |
That's a great clue 😄 |
@andria-dev I can definitely reproduce this, but I don't think there's a solution.
With I think we need TypeScript support for this, microsoft/TypeScript#33079 seems to be the relevant issue. In the mean time, I'd rather stick to the ESM syntax. |
How about also adding const { test } = require('ava'); ? |
Our type definition uses ESM syntax; when using CJS with VSCode, the auto-completion assumes the root is accessed through `require('ava').default`. Placate VSCode by adding a mostly hidden default property on the root. This is available through both CJS and ESM imports. We use a proxy so that we don't end up with root.default.default.default chains. Fixes #2539.
#2836 makes this work through |
Our type definition uses ESM syntax; when using CJS with VSCode, the auto-completion assumes the root is accessed through `require('ava').default`. Placate VSCode by adding a mostly hidden default property on the root. This is available through both CJS and ESM imports. We use a proxy so that we don't end up with root.default.default.default chains. Fixes #2539.
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.
I did look if there were separate typings but there is a
index.d.ts
as part of the basic module that's installed.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.The text was updated successfully, but these errors were encountered: