2

Trying to use TS in a RequireJS client application.

In one file jquery library is accessed by: import $ = require("../libs/jquery-3.3.1.slim.min.js"); and in the same directory is the definition file: jquery-3.3.1.slim.min.d.ts copied (and renamed) from the DefinitelyTyped site.

Now I have 293 errors, all from the definition file, mainly TS2702: 'JQuery' only refers to a type, but is being used as a namespace here.

Tried to add as suggested somewhere: declare module '../libs/jquery-3.3.1.slim.min.js' {export = JQuery} but every variation of it gives an error.

To be able to continue I resorted to the <amd-dependency> method.

SiliconValley
  • 1,465
  • 17
  • 30
  • Related: https://stackoverflow.com/questions/32050645/how-to-use-jquery-with-typescript – Paleo Feb 06 '19 at 14:25
  • Thanks, but I work client side, so no npm. Creating a `node_modules` repository will be the last ratio, if all else fails. – SiliconValley Feb 06 '19 at 14:35
  • 1
    I found a very short `jquery.d.ts` somewhere, so I simply load jquery with RequireJS and , added this definition and `declare var $: JQueryStatic`. Even if not elegant seems to work. – SiliconValley Feb 06 '19 at 14:40

0 Answers0