1

After installing jquery and @types/jquery I can't seem to get JQuery to work in my typescript file.

If I use:

import * as $ from 'jquery';
$("#test").addClass("className");

I get the following error on $("#test"):

TS2349: Cannot invoke an expression whose type lacks a call signature.

If I follow WebStorm's recommended change of changing the import to:

import $ from 'jquery';

Then no errors show but when trying to compile the file I get the error:

error TS1192: Module '"C:/Users/Home/Desktop/react/hello-world/node_modules/@types/jquery/index"' has no default export.

I've looked at a dozen other StackOverFlow posts and nothing has helped. Any ideas?

AlwaysNeedingHelp
  • 1,851
  • 3
  • 21
  • 29

1 Answers1

0

Try to add allowSyntheticDefaultImports flag to your tsconfig or --allowSyntheticDefaultImports to your script.

Another option would be to try esModuleInterop flag.

References:

You need TypeScript 1.8.0 or later

Andriy
  • 14,781
  • 4
  • 46
  • 50
  • It doesn't work I'm afraid. I was able to reproduce it from a bare `create-react-app`, installing jquery, importing with `import * as $ from 'jquery';` (or any other variation) in `index.tsx` and compiling with `tsc --jsx react-native *tsx`. There's always some error. – AlwaysNeedingHelp Jan 07 '19 at 13:53