1

I try to use TypeScript. As a former javascript user, I dont want to give up on jQuery.

So I searched my through the internet and found a decent amount of websites who explained how to use it. I use Visual Studio 2012

So this is my first attempt:

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

class Person {

    constructor(name: string) {
        this.name = name;
    }
    name: string;
}

function greeter(person: Person) {
    return "hallo " + person.name;
}

var person = new Person("bert");


$(document).ready(function () {
    var message = greeter(person);
    jQuery("#content")[0].innerHTML = message;
});

I can build the solution, but if I open my website, it got an javascript error:

ReferenceError: $ is not defined

Any ideas?

2
  • 1
    Dumb question but, are you loading jQuery on your page? You're only referencing the jQuery definition, it's not actually being compiled with your .ts, so you still need to add it in a script tag. Commented Oct 21, 2013 at 12:16
  • newbie tuesday... thanks for the help.. Commented Oct 22, 2013 at 7:04

1 Answer 1

3

You need to still load jquery.js (e.g. with a script tag), just like if you weren't using TypeScript.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.