0

I want to use TypeScript just for typings. I don't want to use classes, interfaces, or even use TypeScript definitions. The reason is that I'm using some jQuery plugins that don't have TypeScript definitions and I can't write them because of time constraints.

I keep reading that I should be able to use typings without the other features because TypeScript is based on JavaScript, but I really can't find a way. Consider the code below. I'm not using the jQuery type definition, therefore I get, "Cannot find name $". And again, I don't want to use TypeScript definitions if they don't cover everything I use.

So the TS file does not get transpiled into a JS file. And the build in Visual Studio 2015 fails.

My question is - how can I have this working in Visual Studio 2015? This is my TS file:

class Dto {
    name: string;
    age: number;
}

$.ajax({
    url: "",
    method: "PUT",
    data: {}
})
.then(function (response: Dto) {
    response.age = 16;
});
2
  • 1
    typescript definition is how typescript knows about types, you can't have typed third party libraries without them. Commented Nov 28, 2016 at 22:47
  • TypeScript without type definition is useless. Commented Nov 29, 2016 at 7:00

1 Answer 1

1

Use JQuery without typings

Before to use $, you can declare to the compiler it exists:

declare var $: any;

You can declare every global variables you use as of type any and the compiler won't complain about them.

Use the JQuery typings and a plugin without typings

With TypeScript, each interface can be completed from everywhere. After importing typings for JQuery, the missing members can be added from your own code:

interface JQuery {
  hereAMemberName: any
}
$('body').hereAMemberName // OK

And / or:

interface JQueryStatic {
  hereAMemberName: any
}
$.hereAMemberName // OK
Sign up to request clarification or add additional context in comments.

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.