Typescript cannot find name '$' after importing jquery?

Smartboy

I am using TypeScript 1.4.1, and have a project laid out like so:

scripts/
    libs/
        jquery/
            jquery.d.ts // Latest from DefinitelyTyped
            jquery.js // 2.1.3
        lodash/
            lodash.d.ts // Latest from DefinitelyTyped
            lodash.js // 3.3.1
    main/
        test.ts

My main/test.ts contains the following:

/// <reference path="../libs/lodash/lodash.d.ts" />
/// <reference path="../libs/jquery/jquery.d.ts" />

import _ = require("lodash");
import $ = require("jquery");

function requireExistingElement($el: $.JQuery) {
    if(_.isUndefined($el) || _.isNull($el) || $el.length === 0) {
        throw new Error("It appears the requested element does not exist?");
    }
}

requireExistingElement($("body"));

This is compiled with the following command:

tsc --module amd scripts/main/test.ts

I expect this to run correctly, but when I compile it I get:

scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.

My question is: How do I reference jquery given that the above is not working? Or, am I just doing something wrong?

curpa

change ($el: $.JQuery) to ($el: JQuery)

$ is a variable, so it can't be used in a type annotation. JQuery is an interface, so it can be used in a type annotation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Importing images in TypeScript React - "Cannot find module"

From Dev

TypeScript "tsd install jquery" - cannot find name "document"

From Dev

TypeScript "tsd install jquery" - cannot find name "document"

From Java

Cannot find name 'Omit' in Typescript

From Java

cannot find name it in jest typescript

From Dev

Typescript instanceof - Cannot find name

From Dev

Typescript Cannot find name 'IterableIterator'

From Dev

TypeScript Cannot find name 'hideInstallPromotion'

From Dev

Typescript Cannot find name 'XInterface'

From Dev

Typescript cannot find name 'map'

From Dev

Typescript: Cannot find name 'Proxy'

From Dev

Cannot import name 'MappingProxyType' error after importing functools

From Dev

TypeScript cannot find name IPromise in RxJS definition

From Java

Typescript cannot find name window or document

From Java

typescript error - cannot find name 'process'

From Dev

Typescript cannot find name even though it is referenced

From Dev

angular with typescript error, cannot find name angular

From Dev

ionic2 TypeScript shows error: Cannot find name 'google' and '$', but google map and jquery still works

From Java

Angular and Typescript: Can't find names - Error: cannot find name

From Dev

TS2307: Cannot find module 'angular2/core' while importing Angular2 on TypeScript

From Java

TypeScript getting error TS2304: cannot find name ' require'

From Java

TypeScript error in Angular2 code: Cannot find name 'module'

From Dev

TypeScript reflect-metadata Cannot find name 'Symbol'

From Dev

Inconsistent "Cannot find name 'x'" Typescript errors in VS Code

From Dev

Typescript function generic arguments in function variable `Cannot find name 'React'`

From Dev

Moment.js + TypeScript. Cannot find name moment

From Dev

Typescript function generic arguments in function variable `Cannot find name 'React'`

From Dev

Moment.js + TypeScript. Cannot find name moment

From Dev

Typescript cannot find interface name but know the function defined

Related Related

  1. 1

    Importing images in TypeScript React - "Cannot find module"

  2. 2

    TypeScript "tsd install jquery" - cannot find name "document"

  3. 3

    TypeScript "tsd install jquery" - cannot find name "document"

  4. 4

    Cannot find name 'Omit' in Typescript

  5. 5

    cannot find name it in jest typescript

  6. 6

    Typescript instanceof - Cannot find name

  7. 7

    Typescript Cannot find name 'IterableIterator'

  8. 8

    TypeScript Cannot find name 'hideInstallPromotion'

  9. 9

    Typescript Cannot find name 'XInterface'

  10. 10

    Typescript cannot find name 'map'

  11. 11

    Typescript: Cannot find name 'Proxy'

  12. 12

    Cannot import name 'MappingProxyType' error after importing functools

  13. 13

    TypeScript cannot find name IPromise in RxJS definition

  14. 14

    Typescript cannot find name window or document

  15. 15

    typescript error - cannot find name 'process'

  16. 16

    Typescript cannot find name even though it is referenced

  17. 17

    angular with typescript error, cannot find name angular

  18. 18

    ionic2 TypeScript shows error: Cannot find name 'google' and '$', but google map and jquery still works

  19. 19

    Angular and Typescript: Can't find names - Error: cannot find name

  20. 20

    TS2307: Cannot find module 'angular2/core' while importing Angular2 on TypeScript

  21. 21

    TypeScript getting error TS2304: cannot find name ' require'

  22. 22

    TypeScript error in Angular2 code: Cannot find name 'module'

  23. 23

    TypeScript reflect-metadata Cannot find name 'Symbol'

  24. 24

    Inconsistent "Cannot find name 'x'" Typescript errors in VS Code

  25. 25

    Typescript function generic arguments in function variable `Cannot find name 'React'`

  26. 26

    Moment.js + TypeScript. Cannot find name moment

  27. 27

    Typescript function generic arguments in function variable `Cannot find name 'React'`

  28. 28

    Moment.js + TypeScript. Cannot find name moment

  29. 29

    Typescript cannot find interface name but know the function defined

HotTag

Archive