6

i'm using browserify to import some nodejs modules. All working fine using this sintax:

$ = jQuery = require('jquery');
require('bootstrap');
require('angular');
require('ngRoute');
require('firebase');
require('angularfire');

Now i'm trying to convert that in typescript (using version 1.8) but i can't figure how to do it. I'm using tsify plugin from browserify

i've tried some sintax like

import * as jquery from "jquery";
import * as jQuery from "jquery";
import * as $ from "jquery";

or

declare var jQuery;
declare var $;
import * as jquery from "jquery";
$ = jQuery =jquery;

but it's not working!

4 Answers 4

11

To have 'jQuery' available globally in the browser you need to attach it to the windows object.

This works for me:

import * as $ from "jquery";
(<any>window).jQuery = $

import "bootstrap";

See this answer: Declare Typescript global variable as "module" type

Sign up to request clarification or add additional context in comments.

Comments

1

at the start of your file you have to tell typescript it should know the typescript definitions of nodejs, jquery and so on.

/// <reference path="DEFINITION-FILE.d.ts" />

require is not known before the d.ts file nodejs isn't referenced $ or jquery is not known befor the d.ts file for jquery is not referenced ...

you can find a a large package of typescript definitions on Definitly Typed

http://definitelytyped.org/

i hope this is helpfull

1 Comment

The project compile successfully so it can't be a definitions problem.
0

Have you tried:

import * as $ from "jquery";

Make sure you have jQuery installed:

typings install jquery --save

Comments

0

import $ from "jquery"; is what works here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.