Use jQuery in TypeScript in VS code

I am trying to add jQuery to a TypeScript project in Visual Studio Code. The goal is to use it via $, as I would do in plain JavaScript, WITHOUT providing a jQuery tag in the head of my html.

I have my jquery and its definition set in the project:

Packages

Therefore, $ and intellisense work like a charm:

Vscode

But when I open the page, I get the error: "ReferenceError: $ not defined".

I read several related topics, including this one , but the question is about Visual Studio, and the last answer also suggests loading jQuery via a tag in html, which I am trying to avoid.

So how do I tell the ts compiler to enable jQuery? I cannot import it because there is no export in jQuery. Am I missing something from tsconfig.json?

tsconfig

+4
1

node_modules. - . javascript, ( /// <reference path='...' - ) .

jquery, .

:

  • jquery script html (-, , )
  • , webpack browserify/tsify, /// <reference path='...' import * as $ from "jquery";, script js

: http://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html

, typescript - js, import jquery .

+2

Source: https://habr.com/ru/post/1695685/


All Articles